您的位置:首页 > 编程语言 > Python开发

Sublime Text下配置Python3开发环境

2013-12-15 17:27 435 查看
原来用的是Eclipse+PyDev写一些Python的小脚本,用上Sublime之后,就尝试在Sublime下面写python代码,发现Sublime的编译运行功能只是看起来很美,实际上连输入的功能都没有,于是安装了插件SublimeREPL,ctrl + shift + p 显示命令输入栏,输入SublimeREPL:Python RUN就能运行当前文件,而不输入Run就是进入Python 的命令行。经常用之后只要输入run就可以很方便地运行了,唯一的缺点是不能显示运行中的异常信息。另外,我还安装了All
Autocomplete,Jedi 等等一堆Python语法自动补全插件 ,写代码从未如此简单!不过之后我悲伤地发现,SublimeREPL下面运行的是Python2.7.5,而我同时装了Python2.7.5和Python3.3.0,于是我就手动地添加了一个配置文件夹,让SublimeREPL能够运行Python3,文件夹新建在如下目录下

sublime安装位置\Data\Packages\SublimeREPL\config\
文件夹中包含 Default.sublime-commands 和 Main.sublime-menu 两个文件

Default.sublime-commands 内容如下

[
{
"caption": "SublimeREPL: Python3",
"command": "run_existing_window_command", "args":
{
"id": "repl_python",
"file": "config/Python/Main.sublime-menu"
}
},
{
"caption": "SublimeREPL: Python3 - RUN current file",
"command": "run_existing_window_command", "args":
{
"id": "repl_python_run",
"file": "config/Python3/Main.sublime-menu"
}
}
]


Main.sublime-menu文件内容如下

[
{
"id": "tools",
"children":
[{
"caption": "SublimeREPL",
"mnemonic": "r",
"id": "SublimeREPL",
"children":
[
{"caption": "Python3",
"id": "Python3",

"children":[
{"command": "repl_open",
"caption": "Python3",
"id": "repl_python",
"mnemonic": "p",
"args": {
"type": "subprocess",
"encoding": "utf8",
"cmd": ["python3", "-i", "-u"],
"cwd": "$file_path",
"syntax": "Packages/Python/Python.tmLanguage",
"external_id": "python3",
"extend_env": {"PYTHONIOENCODING": "utf-8"}
}
},
// {"command": "python_virtualenv_repl",
//  "id": "python_virtualenv_repl",
//  "caption": "Python - virtualenv"},
// {"command": "repl_open",
//  "caption": "Python - PDB current file",
//  "id": "repl_python_pdb",
//  "mnemonic": "d",
//  "args": {
//     "type": "subprocess",
//     "encoding": "utf8",
//     "cmd": ["python", "-i", "-u", "-m", "pdb", "$file_basename"],
//     "cwd": "$file_path",
//     "syntax": "Packages/Python/Python.tmLanguage",
//     "external_id": "python",
//     "extend_env": {"PYTHONIOENCODING": "utf-8"}
//     }
// },
{"command": "repl_open",
"caption": "Python3 - RUN current file",
"id": "repl_python_run",
"mnemonic": "d",
"args": {
"type": "subprocess",
"encoding": "utf8",
"cmd": ["python3", "-u", "$file_basename"],
"cwd": "$file_path",
"syntax": "Packages/Python/Python.tmLanguage",
"external_id": "python",
"extend_env": {"PYTHONIOENCODING": "utf-8"}
}
}
]}
]
}]
}
]
保存之后运行Sublime Text 就能在Tools-->SublimeREPL下看到Python3的条目。注意:要确认你可以从命令行中输入命令“Python3”可以运行Python3

试试看,运行Python3,,成功!

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息