问题
I want to run python code in Microsoft Visual Studio Code but it gives an error:
"Linter pylint is not installed"
I installed:
- The VS Code Python extension
- Python3
- Anaconda
How can I install pylint?
回答1:
- Open a terminal (
ctrl+~) - Run the command
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.
This is an issue because the Python extension's settings enable pylint by 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.linting.pylintEnabled": false
回答2:
Check the path pylint has been installed to, by typing which pylint.
You will get something like: /usr/local/bin/pylint
Copy it.
Go to your vscode settings on the preferences tab and find the line that goes
"python.linting.pylintPath": "pylint"
Edit the line to be
"python.linting.pylintPath": "/usr/local/bin/pylint",
replacing "pylint" with the path you got from typing which pylint
Save your changes and reload vscode.
回答3:
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:
// 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.
If you just want to disable it, then use the python.linting.pylintEnabled": false setting as mentioned in Ben Delaney's answer.
回答4:
Try doing this If you're running VS Code on a Windows machine and getting this error (I'm using Windows 10).
Go to the settings and change the python path to the location of YOUR python installation.
i.e
Change: "python.pythonPath": "python"
To: "python.pythonPath": "C:\\Python36\\python.exe"
And then: Save and Reload VS Code.
Now when you get the prompt telling you that "Linter pylint is not installed", Just select the option to 'install 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.
回答5:
This solved the issue for me:
pip install pylint -U
i.e. upgrade the pylint package.
回答6:
I had the same problem. Open the cmd and type:
python -m pip install pylint
回答7:
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:
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.
回答8:
If you are using MacPorts, you may need to activate pylint and autopep8 after you've installed them, i.e.:
sudo port select pylint pylint36
sudo port select autopep8 autopep8-36
回答9:
I had this issue as well and found the error's log regarding permission or something. So, I ran Visual Studio Code with admin. privileges and ran "pip install pylint" in the terminal. Then the error seemed to be fixed.
(I run Visual Studio Code on windows 10.)
回答10:
If your using pipenv then you just have to
pipenv install pylint
to install pylint to your virtual environment
pipenv shell
to activate the environment and thus make pylintavailable. Then start code in that enviroment
code .
Boom! your good to code ;-)
回答11:
I would like to add my trials and my solution following rob3c's answer.
PS: My solution only concern Windows user.
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:
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.
The content of _tools\python3\Scripts\pylint file:
#!python
from pylint import run_pylint
run_pylint()
The solution
My workaround was to create a batch file .vscode\pylint.bat with the following contents:
%PYTHON3_EXE% _prefix\python3\Scripts\pylint %*
(%PYTHON3_EXE% is an environment variable to python3 C:\Python34\python.exe)
and to configure .vscode\settings.json as follow:
// settings.json
"python.linting.pylintPath": "${workspaceFolder}\\.vscode\\pylint.bat",
Result
Log from 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
✓ vscode uses the Pylint version from my toolchain!
回答12:
The following fix works for me. Ubuntu 16 terminal type:
$ 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.
$ /usr/bin/python3.6 -m pip install -U pylint
回答13:
I had this issue this weekend. It seems to have happened because I opened my project in my venv, but also opened a second instance outside of the venv. I never closed either instance - I just shut my PC down and let windows do the work. When I went back and called up VSCode from within my venv, both the project, and the other non-venv window opened. That's when I started seeing this error.
To fix it I had to remove the \.vscode folder from the workspace directory.
来源:https://stackoverflow.com/questions/43272664/linter-pylint-is-not-installed