Sublime text 3搭建Python开发环境及常用插件安装 转载
Sublime text 3搭建Python开发环境及常用插件安装
一、环境准备
1、官方网站地址
2、Windows 10
3、Sublime Text 3 + 官网购买license(Just a suggestion,$80)
购买链接,Sublime Text may be downloaded and evaluated for free, however a license must be purchased for continued use。如果资金紧张,可以搜索破解版License(建议支持正版,本文不再提供破解版License)。
二、安装Sublime Text 3
1、双击下载的.exe文件安装,安装路径不要有中文目录
三、配置Python环境
运行环境
1、打开Tools > Build System > New Build System..
2、点击New Build System后,会生成一个空配置文件,在这个配置文件内覆盖配置信息,本文python安装路径为“D:/Anaconda3”,(注意区分正反斜杠,请将路径换成python实际安装路径),然后按ctrl+s,将文件保存在默认路径,文件名命名为“Python3”
{ "cmd": ["D:/Anaconda3/python.exe","-u","$file"], "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)", "selector": "source.python", }
如图:
3、打开Tools > Build System,选择新建好的Python3即可
![](https://images2018.cnblogs.com/blog/629575/201808/629575-20180813230248521-778731635.png)
测试
1、新建test.py文件,输入简单python语句,按Ctrl+B运行
字体及字号
1、打开Preferences –>>Settings(Settings User),在右侧添加如下代码(font_face及font_size可根据个人喜好更改)
{ "color_scheme": "Packages/Color Scheme - Default/Monokai.sublime-color-scheme", "font_face": "Consolas", "font_size": 14, "ignored_packages": [ "Vintage" ] }
2、效果如下
四、安装Package Control(官网教程)
第一种方法:在线安装
import urllib.request,os,hashlib; h = '6f4c264a24d933ce70df5dedcf1dcaee' + 'ebe013ee18cced0ef93d5f746d80ef60'; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); by = urllib.request.urlopen( 'http://packagecontrol.io/' + pf.replace(' ', '%20')).read(); dh = hashlib.sha256(by).hexdigest(); print('Error validating download (got %s instead of %s), please try manual install' % (dh, h)) if dh != h else open(os.path.join( ipp, pf), 'wb' ).write(by)
注:上面代码仅适用于Sublime Text 3,如果是Sublime Text2请使用如下代码:
import urllib2,os,hashlib; h = '6f4c264a24d933ce70df5dedcf1dcaee' + 'ebe013ee18cced0ef93d5f746d80ef60'; 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()) ); by = urllib2.urlopen( 'http://packagecontrol.io/' + pf.replace(' ', '%20')).read(); dh = hashlib.sha256(by).hexdigest(); open( os.path.join( ipp, pf), 'wb' ).write(by) if dh == h else None; print('Error validating download (got %s instead of %s), please try manual install' % (dh, h) if dh != h else 'Please restart Sublime Text to finish installation')
关掉并重新打开Sublime Text 3,如果在Perferences->package settings中能看到package control这一项,则表示安装成功。
第二种方法:手动安装
1、点击 Preferences > Browse Packages… 菜单
2、Browse up a folder and then into the Installed Packages/ folder
3、Download Package Control.sublime-package and copy it into the Installed Packages/ directory
4、Restart Sublime Text
1、通过Package Control安装其他插件
1.按下Ctrl+Shift+P调出命令面板
2.输入install 调出 Install Package
3.在列表中选中要安装的插件,或者输入插件名,根据命令面板中的过滤结果,选择要安装的插件
2、通过Package Control查看已安装的插件
1. 按下Ctrl+Shift+P调出命令面板
2. 输入"package",在下拉列表找到"Package Control: list packages",选中后回车,可以显示全部插件列表。
五、常用插件介绍及安装
SublimeCodeIntel
介绍
Full-featured code intelligence and smart autocomplete engine
-
Jump to Symbol Definition - Jump to the file and line of the definition of a symbol.
-
Imports autocomplete - Shows autocomplete with the available modules/symbols in real time.
-
Function Call tooltips - Displays information in the status bar about the working function.
支持语言
JavaScript, ES6, Mason, XBL, XUL, RHTML, SCSS, Python, HTML, Ruby, Python, XML, XSLT, Django, HTML5, Perl, CSS, Twig, Less, Smarty, Node.js, Tcl, TemplateToolkit, PHP.
Installation
1.Control+Shift+P打开Package Control控制台
2.输入install,选择关联出来的install package
3.输入sublimecodeintel,然后点击列表提示的sublimecodeintel安装
4.安装完成之后,文本框会出现如下显示,或者可以通过【Preferences>Package Settings】中查看到已安装的sublimecodeintel插件
5.打开preferences->packages settings ->Package Control ->Settings-User,检查是否有如下红框代码,如果没有得手动添加
6.点击preferences中的browse Packages,进入SublimeCodeIntel文件夹,在当前的路径下新建.codeintel文件夹(windows中文件命名的时候为 .codeintel. ),之后进入到 .codeintel文件夹中,新建文件“config.log”文件,打开输入(下文以路径“D:\Anaconda3”为例,实际配置时请根据具体安装路径修改):
"python3":{ "python":"D:/Anaconda3/python.exe", "pythonExtraPaths":[ "D:/Anaconda3/DLLs", "D:/Anaconda3/Lib", "D:/Anaconda3/Lib/lib-tk", "D:/Anaconda3/Lib/site-packages", ] }
如图:
7.保存,重启Sublime Text 3
测试
新建文件并保存为.py文件,输入代码测试
SublimeREPL
介绍
添加快捷键后,可直接运行当前文件,非常方便
-
Launch python in local or remote(1) virtualenv.
-
Quickly run selected script or launch PDB.
-
Use SublimeText Python console with history and multiline input.
使用方法
![](https://images2018.cnblogs.com/blog/629575/201808/629575-20180813204153739-2037178154.png)
代码粘贴:
[ { "keys": ["f5"], "caption": "SublimeREPL: Python - RUN current file", "command": "run_existing_window_command", "args": { "id": "repl_python_run", "file": "config/Python/Main.sublime-menu" } } ]
测试
1、新建test.py文件,例如:
2、上文中SublimeREPL插件设置的快捷键是F5,所以按F5运行成功如下
SublimeTmpl
介绍
安装插件后,可以通过快捷键按照模板快速新建文件
使用方法
1、安装SublimeTmpl插件后,打开Preferences->Package Settings->SublimeTmpl->Settings User,添加以下内容
{ "disable_keymap_actions": false, // "all"; "html,css" "date_format" : "%Y-%m-%d %H:%M:%S", "attr": { "author": "Yong Lee", "email": "honkly@163.com", "link": "http://www.cnblogs.com/honkly/" } }
如图:
2、添加快捷键,打开Preferences->Key Bindings,添加红框中的快捷键代码
[ { "caption": "Tmpl: Create python", "command": "sublime_tmpl", "keys": ["ctrl+alt+n"], "args": {"type": "python"} }, { "keys": ["f5"], "caption": "SublimeREPL: Python - RUN current file", "command": "run_existing_window_command", "args": { "id": "repl_python_run", "file": "config/Python/Main.sublime-menu" } } ]
如图:
![](https://images2018.cnblogs.com/blog/629575/201808/629575-20180813210310957-658045534.png)
测试
打开Sublime Text 3,上文中SublimeTmpl插件设置的快捷键是"Ctrl+alt+n",按快捷键后成功新建文件如下
![](https://images2018.cnblogs.com/blog/629575/201808/629575-20180813210834699-359440590.png)
ColorSublime
介绍
提供了主题更换功能,可根据个人喜好选择
使用方法
1、安装ColorSublime插件完成后,打开Preferences->Color Scheme...,选择主题
Anaconda
介绍
代码提示等许多功能,必备
安装方法
1、Preferences->Package Settings->Anaconda->Settings Default,修改"python_interpreter"为实际Python安装路径
2、Preferences->Package Settings->Anaconda->Settings User,添加如下内容
{ "python_interpreter":"D:/Anaconda3/python.exe", "suppress_word_completions":true, "suppress_explicit_completions":true, "comlete_parameters":true, "swallow_startup_errors":true, "anaconda_linting":false }
如图:
测试
1、打开Sublime Text3,新建任意*.py文件,输入语句测试,如图
</div>
<div class="postDesc">posted @ <span id="post-date">2017-03-22 14:18</span> <a href="https://www.cnblogs.com/honkly/">honkly</a> 阅读(<span id="post_view_count">36733</span>) 评论(<span id="post_comment_count">4</span>) <a href="https://i.cnblogs.com/EditPosts.aspx?postid=6599642" rel="nofollow">编辑</a> <a href="#" onclick="AddToWz(6599642);return false;">收藏</a></div>
</div>
<script type="text/javascript">var allowComments=true,cb_blogId=184628,cb_entryId=6599642,cb_blogApp=currentBlogApp,cb_blogUserGuid='edf8a47d-3bd1-e311-8d02-90b11c0b17d6',cb_entryCreatedDate='2017/3/22 14:18:00';loadViewCount(cb_entryId);var cb_postType=1;</script>