Sublime text3下运行python

1. 打开Sublime text 3 安装package control

使用Ctrl+`快捷键或者通过View->Show Console菜单打开命令行,粘贴如下代码:

import urllib.request,os; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); open(os.path.join(ipp, pf), 'wb').write(urllib.request.urlopen( 'http://sublime.wbond.net/' + pf.replace(' ','%20')).read())

如果顺利的话,此时就可以在Preferences菜单下看到Package Settings和Package Control两个菜单了。

(http://www.cnblogs.com/luoshupeng/archive/2013/09/09/3310777.html)

2. 安装 SublimeREPL

Ctrl+shift+p 键入 install packages

稍等片刻后 键入 SublimeREPL 安装即可    (安装不成功时,可更新sublime text后重新尝试)

通过选项Tools->SublimeREPL->Python就可以看到效果了

3. 键位绑定

当然每次通过Tools->SublimeREPL->Python这样的方式比较繁琐

将这样的操作和一个按键如F1绑定后,就会方便很多啦

e.g.打开Preferences->Key Bindings-User,复制一下代码:

{"keys":["f1"],
"caption": "SublimeREPL: Python",
"command": "run_existing_window_command", "args":
{"id": "repl_python",
"file": "config/Python/Main.sublime-menu"}}

Ctrl+s下就好了~

如果还想编译下热乎乎的py代码,可以复制以下代码:

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

如果要同时实现F1 和 F2(复制的时候记得中间加个逗号……):

{"keys":["f1"],
"caption": "SublimeREPL: Python",
"command": "run_existing_window_command", "args":
{"id": "repl_python",
"file": "config/Python/Main.sublime-menu"}}

,

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


https://www.zhihu.com/question/22904994

发布了23 篇原创文章 · 获赞 5 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/CatherineC20150619/article/details/81562279