Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't input unicode in python IDE (Mac OS X)

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.

like image 814
fromClouds Avatar asked Jul 15 '11 00:07

fromClouds


1 Answers

The defaultencoding shouldn't affect here. I had a similar problem and for me the solution was to check the Escape non-ASCII input option in Terminal > Preferences > Settings > Advanced. Also make sure that the Character encoding is set to Unicode (UTF-8) in the same settings page.

like image 188
Samuli Asmala Avatar answered Oct 20 '22 08:10

Samuli Asmala