Python 未安装 Linter pylint
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43272664/
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
Linter pylint is not installed
提问by Naveed Aheer
I want to run python code in Microsoft Visual Studio Code but it gives an error:
我想在 Microsoft Visual Studio Code 中运行 python 代码,但它给出了一个错误:
"Linter pylint is not installed"
“未安装 Linter pylint”
I installed:
我安装了:
- The VS Code Python extension
- Python3
- Anaconda
- VS Code Python 扩展
- 蟒蛇3
- 蟒蛇
How can I install pylint?
如何安装pylint?
采纳答案by Ben Delaney
- Open a terminal (
ctrl+~
) - Run the command
pip install pylint
- 打开终端 (
ctrl+~
) - 运行命令
pip install pylint
If that doesn't work:On the off chance you've configured a non-default python path for your editor, you'll need to match that python's install location with the pip executable you're calling from the terminal.
如果这不起作用:如果您为编辑器配置了非默认 python 路径,则需要将该 python 的安装位置与您从终端调用的 pip 可执行文件进行匹配。
This is an issue because the Python extension's settingsenable pylintby default. If you'd rather turn off linting, you can instead change this setting from true
to false
in your user or workspace settings:
这是一个问题,因为 Python 扩展的设置默认启用pylint。如果您想关闭 linting,您可以在您的用户或工作区设置中将此设置从 更改true
为false
:
"python.linting.pylintEnabled": false
回答by Ruto Collins
Check the path pylint has been installed to, by typing which pylint
on your terminal.
通过which pylint
在终端上键入来检查 pylint 已安装到的路径。
You will get something like: /usr/local/bin/pylint
你会得到类似的东西: /usr/local/bin/pylint
Copy it.
复制它。
Go to your vscode settings on the preferences
tab and find the line that goes
转到preferences
选项卡上的 vscode 设置,然后找到该行
"python.linting.pylintPath": "pylint"
"python.linting.pylintPath": "pylint"
Edit the line to be
将行编辑为
"python.linting.pylintPath": "/usr/local/bin/pylint"
,
"python.linting.pylintPath": "/usr/local/bin/pylint"
,
replacing the value "pylint"
with the path you got from typing which pylint
用"pylint"
您输入的路径替换值which pylint
Save your changes and reload vscode.
保存更改并重新加载 vscode。
回答by rob3c
If you're working in a virtual environment (virtualenv), you'll definitely need to update the python.lintint.pylintPath
setting (and probably the python.pythonPath
setting, as well, if you haven't already) if you want linting to work, like this:
如果您在虚拟环境 (virtualenv)中工作,如果您希望 linting 工作,您肯定需要更新python.lintint.pylintPath
设置(可能还有python.pythonPath
设置,如果您还没有更新),就像这样:
// settings.json (workspace-specific one is probably best)
{
// ...
"python.linting.pylintPath": "C:/myproject/venv/Scripts/pylint.exe",
"python.pythonPath": "C:/myproject/venv/Scripts/python.exe",
// ...
}
That's for Windows, but other OSs are similar. The .exe
extension was necessary for it to work for me on Windows, even though it's not required when actually running it in the console.
这适用于 Windows,但其他操作系统类似。该.exe
扩展对于它在 Windows 上为我工作是必要的,即使在控制台中实际运行它时不需要它。
If you just want to disable it, then use the python.linting.pylintEnabled": false
setting as mentioned in Ben Delaney's answer.
如果您只想禁用它,请使用Ben Delaney's answer 中python.linting.pylintEnabled": false
提到的设置。
回答by Ashil John
Try doing this If you're running VS Code on a Windows machine and getting this error (I'm using Windows 10).
如果您在 Windows 机器上运行 VS Code 并收到此错误,请尝试执行此操作(我使用的是 Windows 10)。
Go to the settings and change the python path to the location of YOUR python installation.
转到设置并将python路径更改为您的python安装位置。
i.e
IE
Change: "python.pythonPath": "python"
改变: "python.pythonPath": "python"
To: "python.pythonPath": "C:\\Python36\\python.exe"
到: "python.pythonPath": "C:\\Python36\\python.exe"
And then: Save and Reload VS Code.
然后:保存并重新加载 VS 代码。
Now when you get the prompt telling you that "Linter pylint is not installed", Just select the option to 'install pylint'.
现在,当您收到提示“未安装 Linter pylint”时,只需选择“安装 pylint”选项即可。
Since you've now provided the correct path to your Python installation, the pylint installation will be successfully completed in the Windows Powershell Terminal.
由于您现在已经提供了正确的 Python 安装路径,因此 pylint 安装将在 Windows Powershell 终端中成功完成。
回答by Bob
This solved the issue for me:
这为我解决了这个问题:
pip install pylint -U
i.e. upgrade the pylint
package.
即升级pylint
包。
回答by Dissa
I had the same problem. Open the cmd and type:
我有同样的问题。打开cmd并输入:
python -m pip install pylint
回答by Aeroradish
I also had this problem. If you also have Visual Studio installed with the Python extension, the system will want to use Studio's version of Python. Set the Environment Path to the version in Studio's Shared folder. For me, that was:
我也有这个问题。如果您还安装了带有 Python 扩展的 Visual Studio,系统将要使用 Studio 的 Python 版本。将环境路径设置为 Studio 共享文件夹中的版本。对我来说,那是:
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\
After that, run
之后,运行
python -m pip install pylint
from a command prompt with Administrator rights.
从具有管理员权限的命令提示符。
回答by CpILL
If your using pipenvthen you just have to
如果你使用pipenv那么你只需要
pipenv install pylint
to install pylint to your virtual environment
将 pylint 安装到您的虚拟环境
pipenv shell
to activate the environment and thus make pylint
available. Then start code
in that enviroment
激活环境,从而使之pylint
可用。然后code
在那个环境下开始
code .
Boom!your good to code ;-)
繁荣!你很擅长编码;-)
回答by Sirius
I would like to add my trials and my solution following rob3c's answer.
我想在rob3c 的回答之后添加我的试验和我的解决方案。
PS: My solution only concern Windowsuser.
PS:我的解决方案只涉及Windows用户。
The problem:
问题:
I tried the following settings without success:
我尝试了以下设置但没有成功:
// settings.json
"python.linting.pylintPath": ${workspaceFolder}\_tools\python3\Scripts\pylint
and
和
"python.linting.pylintPath": ${workspaceFolder}\_tools\python3\Scripts\pylint.exe
I always had the following error message:
我总是收到以下错误消息:
Linter 'pylint' is not installed. Please install it or select another linter".
Error: spawn c:\WS\myproject\_tools\python3\Scripts\pylint ENOENT
Even with a pylint file in my folder:
即使在我的文件夹中有一个 pylint 文件:
dir c:\WS\myproject\_tools\python3\Scripts\
...
05.07.2017 09:34 AM 52 pylint # ! no pylint.exe !
...
As my toolchain is based on msys
, the pylint installed is without pylint.exe.
由于我的工具链基于msys
,安装的 pylint没有 pylint.exe。
The content of _tools\python3\Scripts\pylint
file:
_tools\python3\Scripts\pylint
文件内容:
#!python
from pylint import run_pylint
run_pylint()
The solution
解决方案
My workaround was to create a batch file .vscode\pylint.batwith the following contents:
我的解决方法是创建一个包含以下内容的批处理文件.vscode\pylint.bat:
%PYTHON3_EXE% _prefix\python3\Scripts\pylint %*
(%PYTHON3_EXE% is an environment variable to python3 C:\Python34\python.exe
)
(%PYTHON3_EXE% 是 python3 的环境变量C:\Python34\python.exe
)
and to configure .vscode\settings.json as follow:
并配置 .vscode\settings.json 如下:
// settings.json
"python.linting.pylintPath": "${workspaceFolder}\.vscode\pylint.bat",
Result
结果
Log from OUTPUT
--> Python
:
从OUTPUT
-->登录Python
:
##########Linting Output - pylint##########
c:\WS\myproject>C:\Python34\python.exe _tools\python3\Scripts\pylint
--rcfile c:\WS\framework\pylintrc
--msg-template='{line},{column},{category},{msg_id}:{msg}'
--reports=n
--output-format=text
c:\WS\myproject\myScriptToLint.py
Using config file c:\WS\myproject\pylintrc
------------------------------------
Your code has been rated at 10.00/10
? vscodeuses the Pylint version from my toolchain!
? vscode使用我工具链中的Pylint版本!
回答by menhaj
The following fix works for me. Ubuntu 16 terminal type:
以下修复对我有用。Ubuntu 16 终端类型:
$ pip3 install pylint
$ sudo apt install python3-pip
if your python3 is installed in the /usr/bin/python3.6, run the following command, and it should work fine. Last, make sure your VS-code is running python3 interpreter not python2.7 which is default in Ubuntu.
如果你的python3安装在/usr/bin/python3.6,运行以下命令,应该可以正常工作。最后,确保您的 VS 代码运行的是 python3 解释器,而不是 Ubuntu 中默认的 python2.7。
$ /usr/bin/python3.6 -m pip install -U pylint