sublime text 3 打造python3环境(代码自

最近用python3用的比较多,于是整理一下环境,此博客仅记录下自己构造python3环境的过程(sublime text 3版本为3176):

安装的一些常用插件和配置过程如下:
sublime 下载地址,插件安装方法参考另一篇博客
blog.csdn.net/zxy98787267…

  • TrailingSpaces高亮显示多余的空格和Tab
  • BracketHighlighter高亮显示匹配的括号、引号和标签
  • ChineseLocalizations各国语言包
  • SublimeREPL 可以用于运行和调试一些需要交互的程序(可以直接运行当前程序,或者使用ipython、pdb调试代码)

SublimeREPL 安装完成以后,可以通过Tools—SublimeREPL—Python,运行当前的程序;
使用ctrl+b运行程序,步骤如下:
更改配置前先要设置python编译系统,Tools->Build System->New build Systems,将内容改为以下内容

1
2
3
4
5
6
swift复制代码{
"cmd": ["C:/Users/AppData/Local/Programs/Python/Python36-32/python.exe","-u","$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python",
"encoding": "cp936",
}

python.exe为自己电脑上python的路径,encoding的查看方法为:win+R,进入cmd,点击属性进入如下界面:
这里写图片描述

将文件命名为python3.sublime-build,保存退出!
进入Tools->Build System,选择刚才命名的python3,配置完成后,此时ctrl+b可以运行当前程序。

也可以根据习惯配置运行程序的快捷键,打开Preferences->Browse Packages->SublimeREPL->config->Python->Default.sublime-commands,文件如下:

1
css复制代码[    {        "caption": "SublimeREPL: Python",        "command": "run_existing_window_command", "args":        {            "id": "repl_python",            "file": "config/Python/Main.sublime-menu"        }    },    {        "caption": "SublimeREPL: Python - PDB current file",        "command": "run_existing_window_command", "args":        {            "id": "repl_python_pdb",            "file": "config/Python/Main.sublime-menu"        }    },    {        "caption": "SublimeREPL: Python - RUN current file",        "command": "run_existing_window_command", "args":        {            "id": "repl_python_run",            "file": "config/Python/Main.sublime-menu"        }    },    {        "command": "python_virtualenv_repl",        "caption": "SublimeREPL: Python - virtualenv"    },    {        "caption": "SublimeREPL: Python - IPython",        "command": "run_existing_window_command", "args":        {            "id": "repl_python_ipython",            "file": "config/Python/Main.sublime-menu"        }    }]

将此处配置复制到Preferences->key bindings,定义自己的快捷键,如:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
css复制代码[{ "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": ["f1"], "caption": "SublimeREPL: Python",
"command": "run_existing_window_command", "args":
{
"id": "repl_python",
"file": "config/Python/Main.sublime-menu"
}
}
]

配置完成后,保存即可,若需要配置ipython等调试工具的快捷键,配置类似!

“F1”,进入如下python IDE界面
这里写图片描述
“F5”,进入如下执行程序界面
这里写图片描述

  • AutoPep8 调整Python代码,使其符合PEP8的要求(ctrl+shift+8)
  • SideBarEnhancements侧边栏增强
  • SublimeTmpl插件,新建以预设好的Python模板文件,但是该插件功能没有FileHeader功能强大
  • FileHeader能够自动的监测创建新文件动作,自动的添加模板。因此你可以用别的插件创建新文件,FileHeader会自动的给你添加模板
    这里写图片描述
  • Terminal 调出Windows的控制台,用于各种命令操作
    Preferences->Package Settings->Terminal->settings user中配置:
1
2
3
4
swift复制代码{
"terminal": "C:\\Windows\\System32\\cmd.exe",
"parameters": ["/START","%CWD%"]
}

保存即可,使用快捷键ctrl+shift+t打开cmd命令窗口
这里写图片描述

  • Anaconda代码自动补齐
    直接在package control 搜索安装即可,安装完成后,可适当根据自己习惯进行配置,Anaconda ->settings user配置如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
json复制代码{
//由于Anaconda插件本身无法知道Python安装的路径,所以需要设置Python主程序的实际位置
"python_interpreter": "C:/Users/AppData/Local/Programs/Python/Python36-32/python.exe",
//忽略各种空格不对, 超过79字, import的函数没有使用的提醒,
"pep8_ignore": ["E501", "W292", "E303", "W391", "E225", "E302", "W293", "E402"],
"pyflakes_explicit_ignore":
[
"UnusedImport"
],
//保存文件后自动pep8格式化
"auto_formatting": true,
"auto_formatting_timeout": 5,
//库函数的提示
"enable_signatures_tooltip": true,
"merge_signatures_and_doc":true,

//ST3也有自动补全提示,但只提示文件中输入过的单词,这个功能可用提示变量可用的函数等。
"suppress_word_completions": true,
"suppress_explicit_completions": true,
"complete_parameters": true,
//代码排版时,行的默认长度太短,根据喜好设置
"pep8_max_line_length": 120,


}

配置完成后,即可使用代码自动提示功能!详细的配置可以参考官方文档:
damnwidget.github.io/anaconda/ID…

  • SublimeGit 可以使用git的常用命令

安装前需要在电脑上安装git,然后将git的bin目录配置在环境变量中,此处不详述;然后使用package control 安装SublimeGit即可!安装后,使用ctrl+shift+p输入git命令即可!

这里写图片描述

  • Sublime GitHub可以直接在Sublime中打开与GitHub关联的网址
    这里写图片描述
  • SublimeHighlight
    打开Package Control,输入 Add Repository,在下方的url地址栏输入:
1
bash复制代码https://github.com/n1k0/SublimeHighlight/tree/python3

回车,即可安装SublimeHighlight插件。

其他配置:

Preferences -> Settings - User

1
2
3
4
5
6
7
8
9
10
11
json复制代码{
"ignored_packages":
[
"Vintage"
],
"tab_size": 4,
"translate_tabs_to_spaces": true,
"word_wrap": true,
"update_check": false,
"font_size": 12
}
  • 删除已安装的插件

如果已经安装了某些插件,发现不喜欢,可以删除已经安装的插件,进入package control,搜索remove package,进入后选择要删除的插件即可!

更多插件请参考python.jobbole.com/81312/,查看是否…

本文转载自: 掘金

开发者博客 – 和开发相关的 这里全都有

0%