Sublime Text3 配置Python3运行环境

 

创建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"}
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章