参考资料:https://www.cnblogs.com/net66/p/5598383.html
安装PackageResourceViewer插件
- 输入
Ctrl+Shift+P
- 输入
install
,选择Package Control: Install Package
- 选择
PackageResourceViewer
,安装
设置默认的 Python.sublime-build
- 输入
Ctrl+Shift+P
- 输入
resource
,选择PackageResourceViewer:Open Resource
- 再选择
Python
,再再选择Python.sublime-build
编辑
Python.sublime-build
将"shell_cmd": "python -u \"$file\"",
改为以下之一:
"shell_cmd": "python3 -u \"$file\"", //指定python3为.py默认编译器
"shell_cmd": "python2 -u \"$file\"", //指定python2为.py默认编译器
"shell_cmd": "python -u \"$file\"", //根据Ubuntu系统设置,看/usr/bin/python链接哪儿(ln)
"shell_cmd": "指定版本python的绝对路径 -u \"$file\"", //指定路径下的python编译器
使用python3的配置文件示例1(Python.sublime-build)
{
//"shell_cmd": "python -u \"$file\"",
"shell_cmd": "python3 -u \"$file\"", //指定python3为.py默认编译器
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python",
"env": {"PYTHONIOENCODING": "utf-8"},
"variants":
[
{
"name": "Syntax Check",
"shell_cmd": "python -m py_compile \"${file}\"",
}
]
}
使用python3的配置文件示例2(Python.sublime-build)
{
//"shell_cmd": "python -u \"$file\"",
"shell_cmd": "/home/yy430/anaconda3/bin/python -u \"$file\"", //指定anacondad的python3为.py默认编译器
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python",
"env": {"PYTHONIOENCODING": "utf-8"},
"variants":
[
{
"name": "Syntax Check",
"shell_cmd": "python -m py_compile \"${file}\"",
}
]
}
- Ctrl+S 保存配置文件
注:有关.sublime-build
的配置信息说明,可见参见这儿- 重启Sublime Text 3
- 打开.py文件,Ctrl + B 即可编译执行