不能使Eclipse(Luna)PyDev控制台使用UTF-8 [英] Can't make Eclipse (Luna) PyDev console use UTF-8

查看:295
本文介绍了不能使Eclipse(Luna)PyDev控制台使用UTF-8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Eclipse Luna(4.0.4)/ Python 3.4.1中我无法让PyDev 3.6.0控制台使用Unicode,尽管尝试了几个推荐的修正步骤。

In Eclipse Luna (4.0.4) / Python 3.4.1 I can't get the PyDev 3.6.0 console to work with Unicode despite having tried several recommended corrective steps.

我在Dive Into Python 3中尝试了这个例子: http://www.diveintopython3.net/files .html

I attempted this example in Dive Into Python 3: http://www.diveintopython3.net/files.html

如果我执行示例的 a_file.read(),PyDev控制台将显示:

If I do the example's a_file.read(), the PyDev console displays:


'潜入Python \\\是\\\为\\\有\\\经\\\验 ......'而不是潜入Python为有经验的程序员编写一本...'

'Dive Into Python \u662f\u4e3a\u6709\u7ecf\u9a8c......' instead of 'Dive Into Python 是为有经验的程序员编写的一本...'

如果我将中文字符粘贴到PyDev控制台中ala cstring ='是为有经验的程序员编写一本',然后在控制台键入cstring ENTER,我再次得到'\\\是\\\为\\\有\\\经\\\验。 ..'

If I paste the Chinese characters into the PyDev console ala cstring = '是为有经验的程序员编写的一本', then in the console type "cstring ENTER', I again get '\u662f\u4e3a\u6709\u7ecf\u9a8c...'

如果我尝试打印(cstring),我得到了g错误:

If I then try print(cstring), I get the following error:


追溯(最近的最后一次呼叫):
文件,第1行,
文件C:\Python34\lib\encodings\cp1252.py,第19行,编码
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap'编解码器无法编码位置0-13中的字符:字符映射到

Traceback (most recent call last): File "", line 1, in File "C:\Python34\lib\encodings\cp1252.py", line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_table)[0] UnicodeEncodeError: 'charmap' codec can't encode characters in position 0-13: character maps to

我不知道请执行该信息。 cp1252.py 位是我的困惑的核心,因为我已经告诉Eclipse和PyDev在我可以找到的每个地方使用UTF-8从以下信息开始:​​

I don't know what do do with that information. The cp1252.py bit is at the heart of my confusion because I've told Eclipse and PyDev to use UTF-8 in every place I can find to do that, beginning with the information in the following:

在eclipse Pydev控制台和Idle中打印Unicode

但是,我无法修改site .py,如这些步骤所述,因为 [EclipseInstallDi r] /lib/site.py 不包含encoding =。

However, I cannot modify "site.py" as described in those steps because [EclipseInstallDir]/lib/site.py does not contain "encoding = ".

我无法确定下一步该做什么。

I can't figure out what to do next.

推荐答案

找到它! (至少对于Python 3.4.1,Eclipse Luna 4.0.4,PyDev 3.6.0)

Found it! (At least for Python 3.4.1, Eclipse Luna 4.0.4, PyDev 3.6.0.)

在Eclipse中,在首选项 - > PyDev - > 口译 - > Python解释器,在环境选项卡中,我添加了环境变量 PYTHONIOENCODING ,并将其值指定为 utf-8

In Eclipse, in Preferences —> PyDev —> Interpreters —> Python Interpreter, in the Environment tab, I added the environment variable PYTHONIOENCODING and specified its value as utf-8.

PyDev交互式控制台现在可以正确显示上述汉字(和泰语字符也)。

The PyDev Interactive Console now properly displays the aforementioned Chinese characters (and Thai characters, too).

这篇关于不能使Eclipse(Luna)PyDev控制台使用UTF-8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆