使用Sublime Text 3能以輕量級的環境寫python腳本,運行python代碼。爲了更加方便地調用python腳本,經過在Sublime Text 3中綁定快捷鍵的方式,實現一鍵調用python交互運行環境,操做方式以下:python
一、打開 Sublime text 3 安裝 package controllinux
在Tools目錄下點擊安裝Package Control(最後一個)json
二、安裝 SublimeREPLwindows
在Sublime text 3 中,經過快捷鍵 Ctrl+shift+p,鍵入install packages,在彈出的輸入框裏面,輸入SublimeREPL。稍等安裝後,便可看到Tools->SublimeREPL->Python菜單微信
三、綁定快捷鍵 F5(也能夠改成其它快捷鍵)大數據
打開菜單Preferences->Key Bindings-User,而後輸入人工智能
{ "keys": ["f5"], "caption": "SublimeREPL:Python", "command": "run_existing_window_command", "args": { "id": "repl_python_run", "file": "config/Python/Main.sublime-menu" } },
這樣在Sublime Text 3裏面輸入python腳本後,保存爲py文件,而後只要按一下 F5 ,就可以一鍵執行python腳本了code
因爲本人安裝的python有python 2.7和python 3.6兩個版本,默認是python 2.7,因此剛纔按F5快捷鍵後就默認跳到python 2.7的默認環境,若是要定義兩個不一樣的快捷鍵,自由切換python 2.7和python 3.6,那能夠這樣作server
打開目錄 C:\Users\chinamobile\AppData\Roaming\Sublime Text 3\Packages\SublimeREPL\config\Pythonip
把裏面關於cmd python的改成cmd python36。(注:爲區分python 2.7,本機的python 3.6命令爲python36),修改後以下:
[ { "id": "tools", "children": [{ "caption": "SublimeREPL", "mnemonic": "R", "id": "SublimeREPL", "children": [ {"caption": "Python", "id": "Python", "children":[ {"command": "repl_open", "caption": "Python", "id": "repl_python", "mnemonic": "P", "args": { "type": "subprocess", "encoding": "utf8", "cmd": ["python36", "-i", "-u"], "cwd": "$file_path", "syntax": "Packages/Python/Python.tmLanguage", "external_id": "python", "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": ["python36", "-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": "Python - RUN current file", "id": "repl_python_run", "mnemonic": "R", "args": { "type": "subprocess", "encoding": "utf8", "cmd": ["python36", "-u", "$file_basename"], "cwd": "$file_path", "syntax": "Packages/Python/Python.tmLanguage", "external_id": "python", "extend_env": {"PYTHONIOENCODING": "utf-8"} } }, {"command": "repl_open", "caption": "Python - IPython", "id": "repl_python_ipython", "mnemonic": "I", "args": { "type": "subprocess", "encoding": "utf8", "autocomplete_server": true, "cmd": { "osx": ["python36", "-u", "${packages}/SublimeREPL/config/Python/ipy_repl.py"], "linux": ["python36", "-u", "${packages}/SublimeREPL/config/Python/ipy_repl.py"], "windows": ["python36", "-u", "${packages}/SublimeREPL/config/Python/ipy_repl.py"] }, "cwd": "$file_path", "syntax": "Packages/Python/Python.tmLanguage", "external_id": "python", "extend_env": { "PYTHONIOENCODING": "utf-8", "SUBLIMEREPL_EDITOR": "$editor" } } } ]} ] }] } ]
而後在菜單Preferences->Key Bindings-User中,再增長新的快捷鍵,如F6,修改後以下:
[ { "keys": ["f5"], "caption": "SublimeREPL:Python", "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_run", "file": "config/Python/Main-python36.sublime-menu" } }, ]
這樣就完成了,F5就一鍵切換到python 2.7環境,F6就一鍵切換到python 3.6環境,很是方便
歡迎關注本人的微信公衆號「大數據與人工智能Lab」(BigdataAILab),獲取更多信息