Can't input unicode in python IDE (Mac OS X)
Question: I'm trying to collect some unicode raw_input in the default python IDE, and as
far as I'm aware, it should be as simple as:

    
    
    >>> c = raw_input()
    日本語
    >>> print c
    日本語
    

However, when I try to input the unicode characters, the computer beeps some
protestations and I end up with an empty string. (To do this, I click on the
IME switcher near the time and select the appropriate input method [which in
this case is Japanese input). Outside of the python IDE, the input works fine,
I can input the characters and the system recognizes them as having been
input. In the IDE, I'll type some hiragana, and the drop-down kanji selection
window appears as usual, but when I select the appropriate representation and
hit enter, those beeps come and I wind up with nothing. I figure there's a
setting involved somewhere that I've missed.

versions are:

    
    
    Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) 
    [GCC 4.2.1 (Apple Inc. build 5646)] on darwin
    

and

    
    
    Python 2.5.4 (r254:67916, Jun 24 2010, 21:47:25) 
    [GCC 4.2.1 (Apple Inc. build 5646)] on darwin
    

neither of which work. There's also this:

    
    
    >>> import sys
    >>> sys.getdefaultencoding()
    'ascii'
    >>> sys.stdin.encoding
    'UTF-8'
    >>> sys.stdout.encoding
    'UTF-8'
    >>> sys.getfilesystemencoding()
    'utf-8'
    

but from what I've read, the defaultencoding is a mysterious beast. Changing
it doesn't actually fix anything anyway. That is,

    
    
    >>> import sys
    >>> sys.setdefaultencoding('utf-8')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    AttributeError: 'module' object has no attribute 'setdefaultencoding'
    >>> reload(sys)
    <module 'sys' (built-in)>
    >>> sys.setdefaultencoding('utf-8')
    >>> # !!!
    ... c = raw_input()
    no dice!
    

doesn't work. Just more beeping. I can't cut-and-paste Japanese text from
other applications, either.

Any ideas?


Answer: I've had the same problem. In my case it turned out to be a **libedit**
problem. I fixed it by installing readline -- which I had to do from source
(from here: <http://pypi.python.org/pypi/readline>) since using **pip** or
**easy_install** , for whatever reason, didn't actually replace readline.

If you have **ipython** installed, it will tell you on startup if you're using
**libedit**. And, if you have the same experience I did, you'll see the same
problems in both the python interpreter in Terminal and in ipython. Once I got
readline truly installed, and ipython no longer informed me that it was using
libedit, the problems with entering Unicode disappeared in both python and
ipython.

(Note: I also have bpython installed -- and, since it doesn't seem to use
readline or libedit, but rather its own line-editing routines, entering
Unicode in bpython _always_ worked.)

