When I tried to create a build environment for python3 with SublimeText3, I couldn't display Japanese with UnicodeEncodeError, so this is the solution.
If you build the following script of python3 in the default state, you will get UnicodeEncodeError.
tmp.py
# -*- coding: utf-8 -*-
import platform
print(platform.python_version())
print('Japanese')
error
3.4.2
Traceback (most recent call last):
File "/Users/XXXXXXX/Desktop/tmp/tmp.py", line 6, in <module>
print('\u65e5\u672c\u8a9e')
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2: ordinal not in range(128)
[Finished in 0.3s with exit code 1]
[shell_cmd: python -u "/Users/XXXXXXX/Desktop/tmp/tmp.py"]
[dir: /Users/XXXXXXX/Desktop/tmp]
[path: /usr/bin:/bin:/usr/sbin:/sbin]
From Tools => Build System => New Build System ..., enter the following and save as Python3.sublime-build
Since I use pyenv to switch the version, the path is /Users/XXXXXXX/.pyenv/shims/python3, but if it is not installed, check the path with which python3 from the terminal and rewrite it yourself.
Python3.sublime-build
{
"cmd": ["/Users/XXXXXXX/.pyenv/shims/python", "-u", "$file"],
"selector": "source.python",
"file_regex": "file \"(...*?)\", line ([0-9]+)",
"env": {"LANG": "ja_JP.UTF-8"}
}
Recommended Posts