How to change the preferred encoding in Sublime Text 3 for MacOS

杀马特。学长 韩版系。学妹 提交于 2020-01-13 11:43:32

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!