LoginSignup
16
12

More than 5 years have passed since last update.

SublimeText3でpython3のbuild環境を作る

Last updated at Posted at 2015-02-18

SublimeText3でpython3のbuild環境を作ろうとした時,UnicodeEncodeErrorで日本語が表示できなかったのでその解決方法です.

環境

  • Mac OS X Mavericks v10.9.4
  • SublimeText3 Build 3065
  • Python 3.4.2

エラー

デフォルトの状態でpython3の以下のようなスクリプトをbuildするとUnicodeEncodeErrorとなります.

tmp.py
# -*- coding: utf-8 -*-

import platform

print(platform.python_version())
print('日本語')

エラー

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]

解決方法

Tools => Build System => New Build System... から以下のように入力してPython3.sublime-buildで保存

自分はpyenvを使ってversionを切り替えているのでpathが/Users/XXXXXXX/.pyenv/shims/python3ですが,導入していない場合terminalからwhich python3でpathを確認して各自書き換えて下さい.

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"}
}
16
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
12