问题
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())
the output is: UTF-8
When the same code is run in Sublime Text, the output is US-ASCII
.
Setting in the build system for Python 3:
"encoding": "UTF-8"
or
"env": {"PYTHONIOENCODING": "utf-8}
has not helped.
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.
回答1:
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.
Example:
"env": {"PYTHONIOENCODING": "utf-8", "LANG": "en_US.UTF-8"},
This has been confirmed to work on Linux as well as MacOS and Windows.
来源:https://stackoverflow.com/questions/42101759/how-to-change-the-preferred-encoding-in-sublime-text-3-for-macos