在eclipse Pydev控制台和空闲时打印Unicode

Jon*_*han 5 python eclipse unicode console pydev

我的配置:Win7 + Python 2.6 + eclipse + PyDev

如何在以下位置启用Unicode打印语句:

  1. 日食中的PyDev控制台
  2. 闲置Python GUI

打印语句示例:

print(u"???? ????")
Run Code Online (Sandbox Code Playgroud)

这表现为:

ùìåí òåìí
Run Code Online (Sandbox Code Playgroud)

Jon*_*han 11

对于eclipse unicode控制台支持:

  1. 添加-Dfile.encoding=UTF-8eclipse.inieclipse安装目录中.
  2. 在eclipse中 - Run\Run Configurations\Python Run\configuration\Common\确保选择UTF-8
  3. 在eclipse中 - Window\Preferences\General\Workspace\Text file encoding\确保选择UTF-8
  4. [python install path]\Lib\site.py- 换encoding = "ascii"encoding = "utf-8"
  5. 确保你在eclipse中使用unicode支持字体 - Window\Preferences\Appearance\Colors and Fonts\Debug\Console font\Edit

在安装中我完成了以上所有操作:

print(u"???? ????")         # Doesn't work
print("???? ????")          # Works
Run Code Online (Sandbox Code Playgroud)

对于django型号:

print(my_model.my_field)                 # Doesn't work
print(my_model.my_field.encode('utf-8')) # Works
Run Code Online (Sandbox Code Playgroud)

  • 控制台无法正确传达它使用的编码; 设置`PYTHONIOENCODING`环境变量来明确告诉Python. (2认同)