Sublime Text 3 配置python开发环境遇见的问题

来源:互联网 发布:大众mirrorlink 软件 编辑:程序博客网 时间:2024/06/05 07:43

安装的主要插件:


  1. SublimeTmpl 提供了常用文件模板,新建文件时很有用。
  2. Anaconda 是一个终极 Python 插件。它为 ST3 增添了多项 IDE 类似的功能,例如:

  • Autocompletion 自动完成,该选项默认开启,同时提供多种配置选项
  • Goto Definitions 能够在你的整个工程中查找并且显示任意一个变量,函数,或者类的定义。
  • Find Usage 能够快速的查找某个变量,函数或者类在某个特定文件中的什么地方被使用了
  • Code linting 代码静态分析功能,包括格式等,检查使用支持 pep8 标准的 PyLint 或者 PyFlakes
  • SublimeLinter 会帮你查代码是否符合PEP8的要求。有问题有代码会出现白框,点击时底下的状态栏会提示出什么问题。
  • Python PEP8 Autoformat 使用它进行符合PEP8要求的格式化
  • SublimeREPL REPL就是read-evaluation-print-loop,(解释型语言编译运行的过程)。装了SublimeREPL插件后也支持了编辑器上直接的编译运行和交互

我配置过程中遇见的问题和解决方法:

Anaconda的问题

Anaconda默认配置和详细说明
Anaconda配置文件在
Sublime > Preferences > Package Settings > Anaconda > Settings – User:

  {  "pep8_ignore":    [        "E501",    ],    "complete_parameters": true,    "anaconda_linting_behaviour": "save-only",// always    "anaconda_gutter_theme": "hard",    "anaconda_linter_show_errors_on_save": true,    "python_interpreter": "/Library/Frameworks/Python.framework/Versions/3.5/bin/python3",    "anaconda_linting": true,}

a. 代码linting太严

例如:我逗号”,”后面没加空格,它就会用白框框这么提示我代码不规范
这里写图片描述
它管的太严,所以我们可以在pep8_ignore里填入要忽视的错误码,所有错误码

E101 - Reindent all lines.E111 - Reindent all lines.E121 - Fix indentation to be a multiple of four.E122 - Add absent indentation for hanging indentation.E123 - Align closing bracket to match opening bracket.E124 - Align closing bracket to match visual indentation.E125 - Indent to distinguish line from next logical line.E126 - Fix over-indented hanging indentation.E127 - Fix visual indentation.E128 - Fix visual indentation.E129 - Indent to distinguish line from next logical line.E201 - Remove extraneous whitespace.E202 - Remove extraneous whitespace.E203 - Remove extraneous whitespace.E211 - Remove extraneous whitespace.E221 - Fix extraneous whitespace around keywords.E222 - Fix extraneous whitespace around keywords.E223 - Fix extraneous whitespace around keywords.E224 - Remove extraneous whitespace around operator.E225 - Fix missing whitespace around operator.E226 - Fix missing whitespace around operator.E227 - Fix missing whitespace around operator.E228 - Fix missing whitespace around operator.E231 - Add missing whitespace.E241 - Fix extraneous whitespace around keywords.E242 - Remove extraneous whitespace around operator.E251 - Remove whitespace around parameter ‘=’ sign.E261 - Fix spacing after comment hash.E262 - Fix spacing after comment hash.E271 - Fix extraneous whitespace around keywords.E272 - Fix extraneous whitespace around keywords.E273 - Fix extraneous whitespace around keywords.E274 - Fix extraneous whitespace around keywords.E301 - Add missing blank line.E302 - Add missing 2 blank lines.E303 - Remove extra blank lines.E304 - Remove blank line following function decorator.E401 - Put imports on separate lines.E501 - Try to make lines fit withinmax-line-length characters.E502 - Remove extraneous escape of newline.E701 - Put colon-separated compound statement on separate lines.E702 - Put semicolon-separated compound statement on separate lines.E703 - Put semicolon-separated compound statement on separate lines.E711 - Fix comparison with None.E712 - Fix comparison with boolean.W191 - Reindent all lines.W291 - Remove trailing whitespace.W293 - Remove trailing whitespace on blank line.W391 - Remove trailing blank lines.E26 - Format block comments.W6 - Fix various deprecated code (via lib2to3).W602 - Fix deprecated form of raising exception.

或者我们可以关闭anaconda的代码检查”anaconda_linting”: false,
使用Python PEP8 Autoformat 格式化代码

b. anaconda 不能自动补全第三方库

原因是:Anaconda使用的Python版本不是我们系统安装的Python
可通过一下进行配置,使anaconda使用我们电脑上的Python,那样安装在我们电脑上python的第三方库也就会自动导入了
官方配置传送门
如上,关键在”python_interpreter”中写入本机安装的python的完整路径,例如:/Library/Frameworks/Python.framework/Versions/3.5/bin/python3,

SublimeREPL的问题

使用SublimeREPL进行编译运行时,设置SublimeREPL的python为我们机器上的python,不然会出现和上面Anaconda的b一样的问题
解决方法:从电脑目录里找到SublimeREPL/config/Python/Main.sublime-menu文件
例如:Packages/User/SublimeREPL/config/Python/Main.sublime-menu
在Main.sublime-menu文件里配置如下:
我最常用的是用python或者run current file,所以找到这两个,在他们的cmd下填入要关联的本机的python所在的完整目录

{"command": "repl_open",                     "caption": "Python",                     "id": "repl_python",                     "mnemonic": "P",                     "args": {                        "type": "subprocess",                        "encoding": "utf8",                        "cmd": ["/Library/Frameworks/Python.framework/Versions/3.5/bin/python3", "-i", "-u"],                        "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": ["/Library/Frameworks/Python.framework/Versions/3.5/bin/python3", "-u", "$file_basename"],                        "cwd": "$file_path",                        "syntax": "Packages/Python/Python.tmLanguage",                        "external_id": "python",                        "extend_env": {"PYTHONIOENCODING": "utf-8"}                        }                    },

that’s all ! thank you !

1 0