Sublime configures the Python3 runtime environment

Added Python3 compilation environment

Tools > Build  System > New Build System

将默认内容替换为:

{
    "cmd": ["python3", "-u", "$file"],
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
    "selector": "source.python"
}

保存为 Python3.sublime-build

Select the Python3 environment

Tools > Build System > Python3

Compile and run with Python3

Ctrl + b

possible problems

question
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)
reason
默认是ascii编码但是输出中包含中文
solve

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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324378190&siteId=291194637