在sublime text3下搭建python开发环境

自己希望的python开发环境并不需要很强大的功能:

  • 自动格式化,遵循一定的编码风格
  • 能够检测语法错误
  • 能够了解函数,类的定义,并能自动跳转到代码的定义处
  • 具备代码自动完成功能

pep8

Python style guide checker,主要是检查python代码风格。

pip install pep8
pip install --upgrade pep8
pep8 --statistics -qq ./parse.py

pyflakes

Like pep8, pyflakes is also a verification tool for python source codes.

Unlikely pep8, pyflakes doesn’t verify the style at all but verify only logistic errors.

pip install pyflakes
pyflakes ./parse.py

autopep8

A tool that automatically formats Python code to conform to the PEP 8 style guide

注意:缩进是错误不是样式,所以是不能修复的,autopep8 requires pep8。

pip install --upgrade autopep8
autopep8 --in-place  --aggressive <filename>

AutoPEP8

Sublime Auto PEP8 Formatting

Automatically formats Python code to conform to the PEP 8 style guide using autopep8 and pep8 modules

Sublime Text > Preferences > Package Settings > AutoPep8 > Settings-User

{
    "settings": {
        "sublimeautopep8": {
            "max-line-length": 79,
            "format_on_save": false,
            "show_output_panel": true,
            "ignore": "E24,E226,E501",
            "syntax_list": ["Python"],
            "file_menu_search_depth": 3
        }
    }
}

可以使用Control + Shift + 8 to format code,也可以选择部分代码 format code

SublimeLinter3

Interactive code linting framework for Sublime Text 3

一个代码静态检查工具框架(linter),在python下推荐安装SublimeLinter-pyflakesSublimeLinter-pep8,大多数linter都需要先安装一些依赖库才能使用,比如SublimeLinter-pyflakes需要安装pyflakes

Sublime Text > Preferences > Package Settings > SublimeLinter > Settings-User 下是全局的配置

SublimeLinter-pep8

This linter plugin for SublimeLinter provides an interface to pep8. It will be used with files that have the Python syntax

SublimeLinter-pyflakes

SublimeLinter plugin for python, using pyflakes

For general information on how SublimeLinter works with settings, please see Settings.
For information on generic linter settings, please see Linter Settings.

In addition to the standard SublimeLinter settings, SublimeLinter-pyflakes provides its own settings. Those marked as Inline Setting may also be used inline.

SublimeCodeIntel

Full-featured code intelligence and smart autocomplete engine,这个文档是我认为写的最好的Sublime插件文档。

该插件支持的功能:

  • Jump to Symbol Definition (Alt+Click调到函数定义处,Control+Shift+space返回Go back)
  • Imports autocomplete(代码自动完成)
  • Function Call tooltips(函数调用说明)

对于python的设置

"Python": {
    "python": "C:\\Python27\\python.exe",
    "codeintel_scan_extra_dir": [], #排除扫描的路径
    "codeintel_scan_files_in_project": true,
    "codeintel_max_recursive_dir_depth": 15,#扫描层级
    "codeintel_scan_exclude_dir":[""] #扫描的目录
}

注意:v3.0以上版本需要安装CodeIntel python库,v2.2.0+st3是目前比较稳定的版本

如何在实践中使用这些插件

  • 安装pep8,autopep8命令行工具,安装AutoPEP8插件,主要使用ctrl+shift+8修复样式上的问题。
  • 安装pyflakes命令行,SublimeLinter-pyflakes插件,主要显示语法错误,可通过Show Errors on Save配置在保存的时候显示错误。
  • sublimeText本身就是python语言开发的,所以直接内置了python解析器,CTRL+B就能运行编写的python代码
  • 安装SublimeCodeIntel插件,主要提供跳转到函数定义处,并可以跳转到调用处,自动完成功能
  • 安装SublimeLinter-pep8插件,主要是查阅样式问题,可通过四种方式查阅样式问题:
    • 通过快捷键操作
    • 选择Tools-SublimeLinter工具选择全部错误
    • ctrl+shift+p打开控制面板显示错误.另外可通过工具栏选择Show Errors on Save
    • 右键选择操作

anaconda

anaconda是一个比较强大的IDE,说明文档

    原文作者:虞大胆的叽叽喳喳
    原文地址: https://www.jianshu.com/p/c9cc9cdaa5d5
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞