Sublime配置Python3執行環境
阿新 • • 發佈:2019-01-05
新增Python3編譯環境
Tools > Build System > New Build System
將預設內容替換為:
{
"cmd": ["python3", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
儲存為 Python3.sublime-build
選中Python3環境
Tools > Build System > Python3
使用Python3編譯執行
Ctrl + b
可能遇到的問題
問題
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)
原因
預設是ascii編碼但是輸出中包含中文
解決
Preferences > Browse Packages > Users > Python3.sublime-build
修改配置檔案, 配置檔案中新增一條
"env": {"LANG": "en_US.UTF-8"}
修改後如下:
{
"cmd" : ["python3", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python",
"env": {"LANG": "en_US.UTF-8"}
}