首先须要安装Package Control,若是没有安装过的话。python
使用Ctrl+`(不是单引号哈,在键盘左上角位置)快捷键或者经过View->Show Console菜单打开命令行。shell
使用Sublime Text 3的,粘贴以下代码:
ui
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())url |
若是是 Sublime Text 2,使用代码以下:
spa
import urllib2,os; pf='Package Control.sublime-package'; ipp = sublime.installed_packages_path(); os.makedirs( ipp ) if not os.path.exists(ipp) else None; urllib2.install_opener( urllib2.build_opener( urllib2.ProxyHandler( ))); open( os.path.join( ipp, pf), 'wb').write( urllib2.urlopen( 'http://sublime.wbond.net/' +pf.replace( ' ','%20' )).read()); print( 'Please restart Sublime Text to finish installation').net |
顺利的话,此时就能够在Preferences菜单下看到Package Settings和Package Control两个菜单了。
命令行
1、安装SublimeREPLrest
一、调用ctrl+shift+p,输入:sublimerepl选择并安装;(若是找不到这个sublimerepl,后来输入install package才调出来)
二、而后tools --sublimeREPL--Python你会发现打开了一个python的shell窗口,显然这个并非咱们想要的;
三、继续往下走,选择好咱们要执行的py文件,选择Tools -> SublimeREPL -> Python -> RUN current file,这时候已经支持输入了数据了。code
2、设置快捷键orm
最后,因为每次运行程序都要执行:Tools -> SublimeREPL -> Python -> RUN current file 菜单有点麻烦,因此如今能够考虑给他建立个快捷键。方法以下:
选择主菜单上perferences -- key bindings user 中粘贴以下代码(快捷键红色标示的自定义就能够,我的喜欢F5):
[ {"keys":["f5"], "caption": "SublimeREPL: Python - RUN current file", "command": "run_existing_window_command", "args": { "id": "repl_python_run", "file": "config/Python/Main.sublime-menu" }} ]
这样之后你打开你要运行的Py程序,按下f5(Mac OS X下须要同时按下fn键才能激活功能键选择)就能够直接运行了。
下面的配置将F5设为运行python文件,F6为显示Python控制台,F7为显示Shell控制台,直接加入“Preference-key-binding-user”便可。
[ {"keys":["f5"], "caption": "SublimeREPL: Python - RUN current file", "command": "run_existing_window_command", "args": { "id": "repl_python_run", "file": "config/Python/Main.sublime-menu" } },{"keys":["f6"], "caption": "SublimeREPL: Python", "command": "run_existing_window_command", "args": { "id": "repl_python", "file": "config/Python/Main.sublime-menu" } },{"keys":["f7"], "caption": "SublimeREPL: Shell", "command": "run_existing_window_command", "args": { "id": "repl_shell", "file": "config/Shell/Main.sublime-menu" } } ]