Windows 下 Python unicode 控制台支持

hyp*_*not 6 python windows unicode python-2.7 python-3.x

我正在尝试创建一个环境,允许在 Windows 下的 Python 2.7 和 3.4 中打印 unicode 字符。

通过使用Cmder / ConEmu作为终端,开箱即用地完全支持 UTF-8。

然而,Python 支持并不那么简单。

Python 3.3+

如果我设置chcp 65001,Python 3.3+ 会检测到它并运行良好。

Python 2.7

如果我设置chcp 65001它根本不起作用。Python 会产生错误行,而 IPython 根本不工作。

显然,通过指定set PYTHONIOENCODING=utf-8Python 和 IPython 可以工作并允许打印一些unicode 字符。

例如我可以这样做:

print u'\xc1'
Run Code Online (Sandbox Code Playgroud)

但我做不到

print u'\xc1\xc1'
Run Code Online (Sandbox Code Playgroud)

其产生:IOError: [Errno 0] Error

不过,有总比没有好,至少大多数 Python 2.7 程序无需修改即可运行。

我的问题是,如果我添加

@chcp 65001 > nul
@set PYTHONIOENCODING=utf-8
Run Code Online (Sandbox Code Playgroud)

到最后cmder/vendor/init.bat,这会对 Python 3.3+ 产生任何副作用吗?

另外,有什么办法可以让未经修改的Python脚本print u'\xc1\xc1'在Windows下运行吗?