为啥 python Visual Studio 代码中没有显示 pylint 的错误曲线?

Posted

技术标签:

【中文标题】为啥 python Visual Studio 代码中没有显示 pylint 的错误曲线?【英文标题】:why are pylint's error squiggle lines not showing in python visual studio code?为什么 python Visual Studio 代码中没有显示 pylint 的错误曲线? 【发布时间】:2020-05-01 12:26:30 【问题描述】:

我在 Ubuntu 中为 python3 使用 vscode。 Error-squiggle-lines 已停止为 Python 工作(它适用于其他语言)。我正在使用微软的 Python 扩展。vscode v1.41.1 Ubuntu v18.04

这是我尝试过的:

我想可能是因为我安装了 anaconda 所以卸载它但没有修复它。 然后我在从 .config/code 删除其配置后重新安装了 vs 代码,但这也没有用。 还可以从命令面板将 python linting 设置为 true

它没有显示错误曲线:

这是微软的 python 扩展对 linting 的贡献(抱歉可读性差):

Whether to lint Python files.   true python.linting.flake8Args  Arguments passed in. Each argument is a separate item in the array.  python.linting.flake8CategorySeverity.E    Severity of Flake8 message type 'E'.    Error python.linting.flake8CategorySeverity.F   Severity of Flake8 message type 'F'.    Error python.linting.flake8CategorySeverity.W   Severity of Flake8 message type 'W'.    Warning python.linting.flake8Enabled    Whether to lint Python files using flake8   false python.linting.flake8Path Path to flake8, you can use a custom version of flake8 by modifying this setting to include the full path.  flake8 python.linting.ignorePatterns    Patterns used to exclude files or folders from being linted.    .vscode/*.py,**/site-packages/**/*.py python.linting.lintOnSave Whether to lint Python files when saved.    true python.linting.maxNumberOfProblems Controls the maximum number of problems produced by the server. 100 python.linting.banditArgs   Arguments passed in. Each argument is a separate item in the array.  python.linting.banditEnabled   Whether to lint Python files using bandit.  false python.linting.banditPath Path to bandit, you can use a custom version of bandit by modifying this setting to include the full path.  bandit python.linting.mypyArgs  Arguments passed in. Each argument is a separate item in the array. --ignore-missing-imports,--follow-imports=silent,--show-column-numbers python.linting.mypyCategorySeverity.error    Severity of Mypy message type 'Error'.  Error python.linting.mypyCategorySeverity.note  Severity of Mypy message type 'Note'.   Information python.linting.mypyEnabled  Whether to lint Python files using mypy.    false python.linting.mypyPath   Path to mypy, you can use a custom version of mypy by modifying this setting to include the full path.  mypy python.linting.pycodestyleArgs Arguments passed in. Each argument is a separate item in the array.  python.linting.pycodestyleCategorySeverity.E   Severity of pycodestyle message type 'E'.   Error python.linting.pycodestyleCategorySeverity.W  Severity of pycodestyle message type 'W'.   Warning python.linting.pycodestyleEnabled   Whether to lint Python files using pycodestyle  false python.linting.pycodestylePath    Path to pycodestyle, you can use a custom version of pycodestyle by modifying this setting to include the full path.    pycodestyle python.linting.prospectorArgs   Arguments passed in. Each argument is a separate item in the array.  python.linting.prospectorEnabled   Whether to lint Python files using prospector.  false python.linting.prospectorPath Path to Prospector, you can use a custom version of prospector by modifying this setting to include the full path.  prospector python.linting.pydocstyleArgs    Arguments passed in. Each argument is a separate item in the array.  python.linting.pydocstyleEnabled   Whether to lint Python files using pydocstyle   false python.linting.pydocstylePath Path to pydocstyle, you can use a custom version of pydocstyle by modifying this setting to include the full path.  pydocstyle python.linting.pylamaArgs    Arguments passed in. Each argument is a separate item in the array.  python.linting.pylamaEnabled   Whether to lint Python files using pylama.  false python.linting.pylamaPath Path to pylama, you can use a custom version of pylama by modifying this setting to include the full path.  pylama python.linting.pylintArgs    Arguments passed in. Each argument is a separate item in the array.  python.linting.pylintCategorySeverity.convention   Severity of Pylint message type 'Convention/C'. Information python.linting.pylintCategorySeverity.error Severity of Pylint message type 'Error/E'.  Error python.linting.pylintCategorySeverity.fatal   Severity of Pylint message type 'Fatal/F'.  Error python.linting.pylintCategorySeverity.refactor    Severity of Pylint message type 'Refactor/R'.   Hint python.linting.pylintCategorySeverity.warning  Severity of Pylint message type 'Warning/W'.    Warning python.linting.pylintEnabled    Whether to lint Python files using pylint.  true python.linting.pylintPath  Path to Pylint, you can use a custom version of pylint by modifying this setting to include the full path.  pylint python.linting.pylintUseMinimalCheckers  Whether to run Pylint with minimal set of rules.    true

python.linting.pylintEnabled 是:true

python.linting.pylintPath 是:pylint

Visual Studio 开发者工具控制台中的所有错误:

console.ts:137 [Extension Host] Error Python Extension: 2020-01-18 18:35:53: Failed to serialize gatherRules for DATASCIENCE.SETTINGS [TypeError: Cannot convert object to primitive value  at Array.join (<anonymous>) at Array.toString (<anonymous>) at /home/manik/.vscode/extensions/ms-python.python-2020.1.58038/out/client/extension.js:1:12901 at Array.forEach (<anonymous>)  at Object.l [as sendTelemetryEvent] (/home/manik/.vscode/extensions/ms-python.python-2020.1.58038/out/client/extension.js:1:12818)  at C.sendSettingsTelemetry (/home/manik/.vscode/extensions/ms-python.python-2020.1.58038/out/client/extension.js:75:707093) at C.r.value (/home/manik/.vscode/extensions/ms-python.python-2020.1.58038/out/client/extension.js:1:87512) at Timeout._onTimeout (/home/manik/.vscode/extensions/ms-python.python-2020.1.58038/out/client/extension.js:1:86031)    at listOnTimeout (internal/timers.js:531:17)    at processTimers (internal/timers.js:475:7)]
t.log @ console.ts:137
2console.ts:137 [Extension Host] Notification handler 'textDocument/publishDiagnostics' failed with message: Cannot read property 'connected' of undefined
t.log @ console.ts:137
2console.ts:137 [Extension Host] (node:21707) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
t.log @ console.ts:137
$logExtensionHostMessage @ mainThreadConsole.ts:39
_doInvokeHandler @ rpcProtocol.ts:398
_invokeHandler @ rpcProtocol.ts:383
_receiveRequest @ rpcProtocol.ts:299
_receiveOneMessage @ rpcProtocol.ts:226
(anonymous) @ rpcProtocol.ts:101
fire @ event.ts:581
fire @ ipc.net.ts:453
_receiveMessage @ ipc.net.ts:733
(anonymous) @ ipc.net.ts:592
fire @ event.ts:581
acceptChunk @ ipc.net.ts:239
(anonymous) @ ipc.net.ts:200
t @ ipc.net.ts:28
emit @ events.js:200
addChunk @ _stream_readable.js:294
readableAddChunk @ _stream_readable.js:275
Readable.push @ _stream_readable.js:210
onStreamRead @ internal/stream_base_commons.js:166

pythonoutput 面板中的输出:

User belongs to experiment group 'AlwaysDisplayTestExplorer - control'
User belongs to experiment group 'ShowPlayIcon - start'
User belongs to experiment group 'ShowExtensionSurveyPrompt - enabled'
User belongs to experiment group 'DebugAdapterFactory - experiment'
User belongs to experiment group 'AA_testing - experiment'
> conda --version
> pyenv root
> python3.7 -c "import sys;print(sys.executable)"
> python3.6 -c "import sys;print(sys.executable)"
> python3 -c "import sys;print(sys.executable)"
> python2 -c "import sys;print(sys.executable)"
> python -c "import sys;print(sys.executable)"
> /usr/bin/python3.8 -c "import sys;print(sys.executable)"
> conda info --json
> conda env list
Starting Microsoft Python language server.
> conda --version
> /usr/bin/python3.8 ~/.vscode/extensions/ms-python.python-2020.1.58038/pythonFiles/interpreterInfo.py
> /usr/bin/python3.8 ~/.vscode/extensions/ms-python.python-2020.1.58038/pythonFiles/interpreterInfo.py

如何让曲线再次起作用?

【问题讨论】:

你用什么作为你的 linter?安装了吗? @Boris 我有 Microsoft python 扩展ms-python.python。它说它自己会进行 linting、调试等 我不知道,但是如果您在此处发布他们要求的最后两件事的输出,这可能会对其他人有所帮助github.com/microsoft/vscode-python/issues/… 在Output 面板中的Python 的输出和来自的输出ConsoleDeveloper Tools 面板下 @Boris 我已经添加了您要求的内容。但我只在开发者工具的控制台中添加了错误消息。 【参考方案1】:

确保在您的设置中您没有关闭 linting(特别是 Pylint,如果您想使用它)。还要确保您安装了 Pylint 并且 Python 扩展知道它在哪里(通过创建环境并安装到那里或全局安装并设置 "python.linting.pylintPath")。否则,请检查“输出面板”中“Python”通道的输出,以查看 Pylint 是如何执行的,并确保在您将其复制并粘贴到终端时可以正常工作。

【讨论】:

python.linting.pylintPath 设置为 pylint。我试过$ which pylint 它说“找不到pylint”。所以我用sudo apt-get install pylint 安装了它,它安装了pylint,which pylint 返回了路径。但仍然没有显示错误曲线。(我重新加载了几次 vscode) 请指定pylint 的绝对路径,而不仅仅是命令名。 问题得到解决我已经发布了解决方案。必须在settings.json 文件中添加"python.linting.pylintEnabled":True【参考方案2】:

在您的settings.json 文件中(在命令面板中搜索settings.json),声明以下内容:

"python.linting.pylintEnabled": true, "python.jediEnabled": false

如果您只想在工作区中进行更改,请更改 .vscode 文件夹中的 settings.json 文件

在最新版本的 Visual Studio 代码中,工作区不会从复选框中注册设置,因此您必须在 settings.json 中明确声明要为工作区启用哪些设置。 Flake8 不受此影响。因此,Pylint 和 Microsoft Python 语言服务器似乎无法正常工作。

旁注:从 sys-temd 对 github.com/microsoft/vscode-python/issues 的回复中获得此解决方案

【讨论】:

布尔 JSON 条目需要小写,即"python.linting.pylintEnabled": true【参考方案3】:
pip install -U pylint

解决了我的问题

【讨论】:

【参考方案4】:

如果主要问题是工作区中的那些曲线或一些小错误,那么您可以下载“pylance 扩展”并在“python 语言服务器”的设置中启用它。这个语言服务器甚至更好(我认为),因为它比“绝地”语言服务器更轻,并且还告诉那些未使用的模块和变量,甚至是未定义的变量,如那些曲线所示。

【讨论】:

【参考方案5】:

我试过但没用

    pip install -U pylint 声明"python.linting.pylintEnabled": true, "python.jediEnabled": false

然后我尝试重新创建一个全新的 settings.json,结果 pylint 工作正常。

因此,我追踪哪条线影响了 pylint。

在我的例子中,它是从"python.linting.pylintArgs":开始的那一行

解决方案

删除从"python.linting.pylintArgs": 开始的行将解决问题。

【讨论】:

我使用的是 flake8 并且遇到了这个问题。我想通过从 VSCode 传递参数来告诉它我允许的最大行长是多少。但是我弄错了,它停止抱怨线路超支但不知不觉地对我来说,也停止抱怨一切,因为它已经死了,什么都没有告诉我!

以上是关于为啥 python Visual Studio 代码中没有显示 pylint 的错误曲线?的主要内容,如果未能解决你的问题,请参考以下文章

Visual studio 2017???????????????????????????????????????ReferenceManagerPackage??????????????????(代

Visual Studio Code - 没有 ptvsd 的远程调试

为啥Visual Studio这么垃圾?

为啥visual studio 2013安装后,没有c#模板?

第一次安装过visual studio2005删了,再第二次安装就安装不起来了!为啥?

visual studio 2008的ISO文件有3.70GB,为啥有这么大?