sublime执行python含有中文代码结果报错,报错如下
Traceback (most recent call last):
File "/Users/stacywongs/Downloads/python/demo.py", line 2, in <module>print('\u8f93\u5165\u540d\u79f0')
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-3: ordinal not in range(128)
[Finished in 0.0s with exit code 1]
查了几个结果都说在Python.sublime-build加一行
"encoding": "utf-8", 在我mac环境下并未能起作用,执行后还是报错,
查到如下解决方式
"env": {"LANG": "en_US.UTF-8"} 这句话是关键
{
"cmd": ["python", "-u", "$file"],
"path":"/anaconda3/bin",
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python",
"encoding": "utf-8",
"env": {"LANG": "en_US.UTF-8"}
}
--------------------------------引用如下-------------------------------
https://segmentfault.com/q/1010000000398574
http://stackoverflow.com/a/15174760
Preferences -> Browse Packages -> Python
-> Python.sublime-build
加上一句 env
,比如这样:
{
"cmd": ["/usr/local/bin/python3.3", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python",
"env": {"LANG": "en_US.UTF-8"}
}