简体   繁体   English

VS Code 无法识别 pep8

[英]VS Code doesn't recognize pep8

To use linting for Python, I configured VS Code like this:为了对 Python 使用 linting,我这样配置VS Code

"python.linting.enabled": true,
"python.linting.pylintEnabled": false,
"python.linting.pep8Enabled": true,
"python.linting.lintOnTextChange": true,
"python.linting.lintOnSave": true

Then I opened a *.py file and added an unnecessary space and saved, then I got an error: Linter pep8 is not installed .然后我打开一个*.py文件并添加了一个不必要的空间并保存,然后我得到一个错误: Linter pep8 is not installed

But I already installed pep8 .但我已经安装了pep8 And by using VS Code console I can find the pep8 .通过使用 VS Code 控制台,我可以找到pep8

With VS Code console使用 VS Code 控制台

/usr/bin/python -m pip install pep8
loading ~/.zshrc_osx
ironsand@macbook ~ % /usr/bin/python -m pip install pep8
/usr/bin/python: No module named pip
ironsand@macbook ~ % which python
/usr/bin/python
ironsand@macbook ~ % which pep8
/usr/local/bin/pep8
ironsand@macbook ~ % pep8 --version
1.7.0
ironsand@macbook ~ % which python
/usr/bin/python
ironsand@macbook ~ %

Maybe I installed pep8 by using pip2 that is installed brew .也许我使用安装了brew pip2安装了pep8

With OS Console(iTerm2)使用操作系统控制台(iTerm2)

python --version
Python 2.7.10
ironsand@macbook ~ % /usr/local/bin/pip2 install pep8
Collecting pep8
  Using cached pep8-1.7.0-py2.py3-none-any.whl
Installing collected packages: pep8
Successfully installed pep8-1.7.0

What am I doing wrong?我做错了什么?

Plugins插件

MagicPython 1.0.12
Python 0.7.0
Python for VSCode 0.2.3

PEP8 was renamed to pycodestyle . PEP8 被重命名为pycodestyle In the Python VS Code Extension (by Microsoft) it is already renamed in the command palette and in the settings.json file.在 Python VS Code 扩展(由 Microsoft)中,它已在命令面板和 settings.json 文件中重命名。 However the documentation for them are not up-to-date yet and they can be confusing.然而,它们的文档还不是最新的,它们可能会令人困惑。

The problem with pep8 is because vscode now is using flake8, is basically the same, pep8 was renamed to pycodestyle, flake8 use pycodestyle, this is the old config: pep8的问题是因为vscode现在用的是flake8,基本一样,pep8改名为pycodestyle,flake8用的是pycodestyle,这是旧配置:

"python.linting.pep8Enabled": true, // Don't use it

But now you can't find that config in vscode, the new config line now is:但是现在你在 vscode 中找不到那个配置,现在新的配置行是:

"python.linting.flake8Enabled": true, // This is the new config for pep8

If the second option didn't work, you can try this:如果第二个选项不起作用,您可以尝试以下操作:

"python.linting.pycodestyleEnabled": true // You need: pip install pycodestyle

I hope this answer is helpful for you我希望这个答案对你有帮助

May sound trivial, but have you installed Python for vscode?可能听起来微不足道,但是您是否为 vscode 安装了Python The one by DonJayamanne works great. DonJayamanne 的那个效果很好。

If so, try adding your pythonPath to the settings of your vscode editor, at least, it solved the problem for me.如果是这样,请尝试将您的pythonPath添加到您的 vscode 编辑器的settings中,至少,它为我解决了问题。

pep8 path should be auto discovered then, if not, you may want to add your pep8Path as well. pep8应该自动发现pep8路径,如果没有,您可能还想添加您的pep8Path

I know this is an old issue, but I was having the same problem where VS Code wasn't recognizing PEP8.我知道这是一个老问题,但我遇到了同样的问题,即 VS Code 无法识别 PEP8。 An uninstall followed by a reinstall did the trick for me.卸载然后重新安装对我来说很有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM