cx_freeze windows console编码错误

时间:2014-09-24 14:15:32

标签: encoding cx-freeze python-3.4

我有python 3.4脚本,它处理unicode字符,变音符号等。 该脚本在Mac和Windows上完美运行。 如果我将它冻结到Windows可执行文件(在Windows上冻结!)

python cxfreeze verifier.py -cOO --target-dir verifier

并尝试运行它,它会在执行输出时给出以下异常

Traceback (most recent call last):
  File "C:\Python34\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27, in <module>
exec(code, m.__dict__)
  File "C:\Users\me\Desktop\verifier\verifier.py", line 520, in <module>
main()
  File "C:\Users\me\Desktop\verifier\verifier.py", line 484, in main
ConsoleManager.dynamic_print(MSG_VERIFYING_FILE.format(relativePath))
  File "C:\Users\me\Desktop\verifier\verifier.py", line 230, in dynamic_print
ConsoleManager.print(message, end='\r')
  File "C:\Users\me\Desktop\verifier\verifier.py", line 226, in print
print(message, end=end)
  File "X:\Python34-x32\lib\encodings\cp866.py", line 19, in encode
UnicodeEncodeError: 'charmap' codec can't encode character '\u0456' in position 16: character maps to <undefined>

我想知道为什么&#39; cp866&#39;?该脚本仅使用utf-8,并且根本没有cp866字符集引用! 看起来cx_Freeze正在尝试将utf-8流打印到控制台,如cp866流。

如何告诉cx_Freeze exe-creator脚本在utf-8中执行所有控制台输出?

我会很乐意提供任何帮助。

更新:找到http://sourceforge.net/p/cx-freeze/mailman/message/24126644/可能是遇到问题

1 个答案:

答案 0 :(得分:0)

尝试在Windows控制台中执行以下操作:

chcp 65001
set PYTHONIOENCODING=utf-8