Python 如何让 PyCharm 检查 PEP8 代码样式?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17139485/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get PyCharm to check PEP8 code style?
提问by Alvaro
I'm using PyCharm (v 2.7.2) to develop a Django app, but I can't get it to check PEP8 style violations. I have enabled "PEP8 coding style violation" in the "Inspctions" section of the settings, but PyCharm doesn't highlight the style violations. Is there a way to fix this?
我正在使用 PyCharm (v 2.7.2) 来开发 Django 应用程序,但我无法使用它来检查 PEP8 样式违规。我在设置的“检查”部分启用了“PEP8 编码样式违规”,但 PyCharm 没有突出显示样式违规。有没有办法来解决这个问题?
采纳答案by Eric Smith
Which version of Python are you using? If it is Python 3 (maybe specifically Windows 64 bit), there are a couple of bugs logged against that on JetBrains' site:
您使用的是哪个版本的 Python?如果它是 Python 3(可能特别是 Windows 64 位),则在 JetBrains 的站点上记录了一些错误:
http://youtrack.jetbrains.com/issue/PY-8923
http://youtrack.jetbrains.com/issue/PY-8923
回答by Low Kian Seong
For me I found that the best way for me was to include pep8 checking as an external script, something along the lines of this:
对我来说,我发现对我来说最好的方法是将 pep8 检查作为外部脚本包含在内,大致如下:
The advantage of doing this is that the errors appear as sort of a todo list the bottom of the frame. This way I don't have to look around the code for errors.
这样做的好处是错误显示为框架底部的待办事项列表。这样我就不必在代码中寻找错误。
回答by RubberDuckRabbit
Mine wasn't showing up due to the color scheme. By default it's marked as "weak warning", so you might have to edit the appearance to make it visible. Editor > Colors & Fonts > General > Errors and Warnings.
由于配色方案,我的没有出现。默认情况下,它被标记为“弱警告”,因此您可能需要编辑外观以使其可见。编辑器 > 颜色和字体 > 常规 > 错误和警告。
回答by gmauch
OP asks for a way to highlight PEP8 errors on PyCharm, but there's another way (much clearer in my opinion) to see the violations (extracted from PyCharm's docs). Open Code | Inspect Code and friends:
OP 要求一种方法来突出 PyCharm 上的 PEP8 错误,但还有另一种方法(在我看来更清晰)来查看违规行为(摘自PyCharm 的文档)。打开代码 | 检查代码和朋友:
Inspection Tool Window
View | Tool Windows | Inspection:
- You can access the tool window this way only when it is already opened through Code | Inspect Code.
- After you deactivate the tool window manually by clicking the Close button, the tool window is again available only through Code | Inspect Code. The Inspection tool window displays inspection results on separate tabs
检查工具窗口
查看 | 工具窗口 | 检查:
- 只有当工具窗口已经通过 Code | 打开时,您才能以这种方式访问工具窗口。检查代码。
- 通过单击关闭按钮手动停用工具窗口后,工具窗口将再次仅通过 Code | 可用。检查代码。检查工具窗口在单独的选项卡上显示检查结果
Just tested it on a PyCharm Community Editionand it worked like a charm(no pun intended).
刚刚在PyCharm 社区版上对其进行了测试,它就像一个魅力(没有双关语)。
回答by radzak
Well, I wish I had a better answer, but what helped me was simply the following:
好吧,我希望我有一个更好的答案,但对我有帮助的只是以下几点:
- switch the interpreter from a remote one to a system one
- wait until the Pycharm indexing is done
- switch the interpreter back to the initial/desired one
- 将解释器从远程解释器切换到系统解释器
- 等到 Pycharm 索引完成
- 将解释器切换回初始/所需的解释器

