如何在Mac OS的Sublime Text 3中更改首选编码 [英] How to change the preferred encoding in Sublime Text 3 for MacOS
问题描述
我想在优胜美地的Sublime Text 3中将首选编码从US-ASCII更改为UTF-8. bash中的首选编码设置为UTF-8,因此当在终端中运行python时:
I want to change the preferred encoding from US-ASCII to UTF-8 in Sublime Text 3 on Yosemite. The preferred encoding in the bash is set to UTF-8 so when python is run in the terminal:
import locale
print(locale.getpreferredencoding())
输出为:UTF-8
在Sublime Text中运行相同的代码时,输出为US-ASCII
.
the output is: UTF-8
When the same code is run in Sublime Text, the output is US-ASCII
.
在Python 3的构建系统中设置
Setting in the build system for Python 3:
"encoding": "UTF-8"
或
"env": {"PYTHONIOENCODING": "utf-8}
没有帮助.
如何永久更改设置,这样我就不必在脚本中调用locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
作为修复.
How can the setting be changed permanently so that I don't have to call locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
in a script as a fix.
推荐答案
在ST3的Python构建系统中,您可以指定应设置LANG
环境变量,这将影响从locale.getpreferredencoding()
返回的结果,这样您就不需要修改任何Python脚本.
In ST3's build system for Python, you can specify that it should set the LANG
environment variable, and this will affect the result returned from locale.getpreferredencoding()
, so that you don't need to amend any Python scripts.
示例:
"env": {"PYTHONIOENCODING": "utf-8", "LANG": "en_US.UTF-8"},
已确认这可以在Linux以及MacOS和Windows上使用.
This has been confirmed to work on Linux as well as MacOS and Windows.
这篇关于如何在Mac OS的Sublime Text 3中更改首选编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!