How do I enable Pylint in VSCode?
我无法得到pyCode错误以显示在VSCode中。我在全局安装了pylint(sudo apt安装pylint),创建了venv并使用pip将其安装在那里,我在VSCode中选择了pylint作为linter,启用了它,然后运行了它,并且在我的文件中未显示任何错误。如果我从命令行检查,它会在我的文件中显示许多错误。
这在较早的版本中有效,但现在在使用snap安装的VSCode 1.46.1和1.45.1上无效。
与Microsoft和Jedi python语言服务器相同的结果。
我在开发人员控制台中找到了pylint命令:
1 | ~/Documents/work/python/.venv/bin/python ~/.vscode/extensions/ms-python.python-2020.6.89148/pythonFiles/pyvsc-run-isolated.py pylint --disable=all --enable=F,unreachable,duplicate-key,unnecessary-semicolon,global-variable-not-assigned,unused-variable,unused-wildcard-import,binary-op-exception,bad-format-string,anomalous-backslash-in-string,bad-open-mode,E0001,E0011,E0012,E0100,E0101,E0102,E0103,E0104,E0105,E0107,E0108,E0110,E0111,E0112,E0113,E0114,E0115,E0116,E0117,E0118,E0202,E0203,E0211,E0213,E0236,E0237,E0238,E0239,E0240,E0241,E0301,E0302,E0303,E0401,E0402,E0601,E0602,E0603,E0604,E0611,E0632,E0633,E0701,E0702,E0703,E0704,E0710,E0711,E0712,E1003,E1101,E1102,E1111,E1120,E1121,E1123,E1124,E1125,E1126,E1127,E1128,E1129,E1130,E1131,E1132,E1133,E1134,E1135,E1136,E1137,E1138,E1139,E1200,E1201,E1205,E1206,E1300,E1301,E1302,E1303,E1304,E1305,E1306,E1310,E1700,E1701 --msg-template='{line},{column},{category},{symbol}:{msg}' --reports=n --output-format=text ~/Documents/work/python/micro.py |
所以pylint确实被执行了!如果我从命令行这样运行它,则输出为:
1 | Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00) |
但是如果执行
1 | Your code has been rated at -2.50/10 (previous run: 10.00/10, -12.50) |
为什么VSCode使用该命令行?我现在没有.pylintrc进行测试,但是即使有.pylintrc,VSCode也没有显示任何错误,只有命令行!但是我只是再次尝试,添加了一个.pylintrc,由于某种原因,现在错误确实出现在编辑器中!
但这仅适用于Jedi服务器,当尝试使用Microsoft服务器时,无法使用其命令启用linting,什么也没有发生,并且它保持关闭状态。
我的.vscode / settings.json:
1 2 3 4 5 6 7 8 | { "python.linting.pylintEnabled": true, "python.linting.enabled": true, "python.linting.pylintArgs": [ "--rcfile", "${workspaceFolder}/backend/.pylintrc" ] } |
也许一种可能的解决方案是从
这些步骤使您可以从终端(macOS)从VS代码站点启动VS代码。
安装:
从命令行启动:
从
对于Windows和Linux,可以在链接中找到设置路径的步骤。