96

I want to run Python code in Microsoft Visual Studio Code but it gives an error:

Linter pylint is not installed

I installed:

  • The Visual Studio Code Python extension
  • Python 3
  • Anaconda

How can I install Pylint?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Naveed Aheer
  • 1,715
  • 6
  • 25
  • 40

15 Answers15

128

Check the path Pylint has been installed to, by typing which pylint on your terminal.

You will get something like: /usr/local/bin/pylint

Copy it.

Go to your Visual Studio Code settings in 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 the value "pylint" with the path you got from typing which pylint.

Save your changes and reload Visual Studio Code.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Kaka Ruto
  • 4,581
  • 1
  • 31
  • 39
  • 1
    This would be a good approach if the installation happened already. In this case it seems that since pylint isn't there it's not the best approach. – user2867432 Aug 22 '18 at 20:40
  • 1
    @user2867432 The OP states that Anaconda Python is installed, which comes with `pylint` already installed. The problem is that Anaconda Python is not automatically added to the path. For those who do not have access/desire to change their path, this is absolutely the best approach. – Steven C. Howell Nov 30 '18 at 15:33
  • VScode does weird stuff here. If I open a terminal inside my vscode project, inside the pipenv I'm using, i can type `flake8` or `pylint` or `which pylint` no problem. Still VSCode seems to require an explicit path. :/ – Antonvh Jan 12 '19 at 17:12
  • The following worked for my Anaconda install on windows `C:\Users\username\AppData\Local\Continuum\Anaconda3\Scripts\pylint.exe`. Not too surprising, it did not work with forward slashes. – Steven C. Howell May 17 '19 at 16:35
  • 3
    Fow windows users, ```which``` is linux command and you must use ```where```. Although for me ```where pylint``` did not help. Hence I just performed ```pip3 install pylint```, which told me the path by: ```Requirement already satisfied: pylint in ``` ```c:\users\keshavb\appdata\roaming\python\python37\site-packages (2.4.2)``` – Kay Jan 24 '20 at 13:27
  • Easier way, just can change the pyLintPath to ```C:\Users\_your_username_AppData\Roaming\Python\Python37\Scripts\pylint.exe``` – Kay Jan 27 '20 at 10:08
  • 1
    This works, but I'd love to know why VSCode isn't using the same `python`, `pip`, and `pylint` that are in the `PATH` of the shell I started it from. – Vince Sep 11 '20 at 09:24
85
  1. Open a terminal (ctrl+~)
  2. 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
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ben Delaney
  • 1,082
  • 11
  • 19
  • pip install pylint command gives this error 'pip' is not recognized as an internal or external command, operable program or batch file – Naveed Aheer Apr 07 '17 at 08:09
  • 4
    This is likely because pip isn't on your path, so you can't run it directly from the terminal. If python is on your path, you should be able to run `python -m pip install pylint`. – Ben Delaney Apr 07 '17 at 08:11
  • If Python isn't on your path, you may want to add it, so you can run Python from the command line in the future. Instructions for adding an executable to your path vary by platform, but should be easy to find. Alternatively, you could just turn off linting, for now :-) – Ben Delaney Apr 07 '17 at 08:17
  • Thanks for your suggestions – Naveed Aheer Apr 08 '17 at 11:01
  • Thank You @Ben for solution – Naveed Aheer Apr 19 '17 at 18:38
  • 2
    See @RutoCollins [solution](https://stackoverflow.com/a/45989777/3585557) for how to configure VS Code to use the pylint already installed (which is installed if, like the OP states, you installed Anaconda Python). If you do not have desire/access to change you `PATH` variable, that is the best option. – Steven C. Howell Nov 30 '18 at 15:35
  • The terminal (`Ctrl-\`` not `Ctrl-~`) uses the same Python environment as the actual shell and pylint is installed. VSCode is using something different and I'm not sure why. – Vince Sep 11 '20 at 09:20
7

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:

// File "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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
rob3c
  • 1,936
  • 1
  • 21
  • 20
  • `pylint.exe` is needed in pylint installation folder. But the `.exe` is not in the `settings.json`. I.e.: `"python.linting.pylintPath": "C:/myproject/venv/Scripts/pylint"` – Sirius Jun 19 '18 at 14:15
7

This solved the issue for me:

pip install pylint -U

I.e., upgrade the pylint package.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Bob
  • 5,809
  • 5
  • 36
  • 53
  • My problem was that the message `Module pylinter not installed` would pop up constantly, but pylinter _was_ installed in both Python2 and Python3. Upgrading pylint from within the terminal (`ctrl+~`) resolved my issue. – DrStrangepork Aug 29 '17 at 17:45
  • This solution worked for me where others didn't. Some systems like Fedora Linux and Python 3.x support need `pip3 install pylint -U` – srking Dec 15 '17 at 21:41
  • 1
    `-U` will upgrade an installed `pylint`, but this doesn't help if VSCode isn't finding `pylint` even though it's installed. – Vince Sep 11 '20 at 09:27
6

Try doing this if you're running Visual Studio 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 Visual Studio 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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ashil John
  • 7,362
  • 4
  • 19
  • 34
4

If you're reading this in (or after) 2020 and are still having issues with Pylint in Visual Studio Code for Windows 10, here is a quick solution that worked for me:

Make sure Python is installed for Windows, and note the installation path.

From an elevated command prompt, go to the installation directory for Python:

cd C:\Users\[username]\Programs\Python\Python[version]\

Install Pylint:

python -m pip install pylint

Pylint is now installed in the 'Python\Python[version]\Scripts\' directory, note/copy the path for later.

Open settings in Visual Studio Code: Ctrl + ','

Type in python.defaultInterpreterPath in the search field, and paste in the path to the Windows installation path for Python:

(e.g. C:\Users\[username]\AppData\Local\Programs\Python\Python[version]\python.exe)

Do the same for python.pythonPath, using the same path as above.

Lastly, search for python.linting.pylintpath and paste the path to pylint.exe.

Restart Visual Studio Code

That got rid of the warnings for me, and successfully enabled pylinting.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
oroshi-tom
  • 41
  • 2
3

I had the same problem. Open the cmd and type:

python -m pip install pylint
Dissa
  • 31
  • 2
2

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.

Aeroradish
  • 371
  • 1
  • 5
  • 11
  • But the question was about [Visual Studio Code](https://en.wikipedia.org/wiki/Visual_Studio_Code), not [Visual Studio](https://en.wikipedia.org/wiki/Microsoft_Visual_Studio). – Peter Mortensen Jan 22 '21 at 11:03
  • @PeterMortensen The comment was "If you also have Visual Studio installed", meaning "in addition to Code". At the time, Windows would reset VS Code's version of Python to whatever Visual Studio's was. In other words, Visual Studio's setting would override VS Code's. I don't know if that's still true now, three years later, but it was then. – Aeroradish Jan 22 '21 at 12:41
1

If you are using MacPorts, you may need to activate package pylint and autopep8 after you've installed them, i.e.:

sudo port select pylint pylint36
sudo port select autopep8 autopep8-36
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jason Dufair
  • 671
  • 8
  • 15
1

I had this issue as well and found the error's log regarding permissions or something.

So, I ran Visual Studio Code with administrator privileges and ran "pip install pylint" in the terminal. Then the error seemed to be fixed.

(I run Visual Studio Code on Windows 10.)

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
cosmos3298
  • 46
  • 4
1

If you're 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 Pylint available. Then start code in that environment

code .

Boom! you're good to code ;-)

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
CpILL
  • 6,169
  • 5
  • 38
  • 37
  • Yep, also if somebody's wondering why it still complains after `pipenv install pylint`, just reload your workspace in VSCode. – vintprox Aug 25 '18 at 21:05
1

The following fix works for me. In a Ubuntu 16.04 (Xenial Xerus) terminal, type:

$ pip3 install pylint
$ sudo apt install python3-pip

If your Python 3 is installed in the /usr/bin/python3.6 folder, run the following command, and it should work fine. Last, make sure your Visual Studio Code is running the Python 3 interpreter, not Python 2.7 which is default in Ubuntu.

$ /usr/bin/python3.6 -m pip install -U pylint
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
menhaj
  • 31
  • 3
1

A similar issue happened to me after I a completely reinstalled Python. Opening the settings.json by Ctrl+ ⇧ Shift+P:

                             

and I saw that I had set the default linter to

"python.linting.pylintPath": "pylint_django"

so opening a terminal (e.g., Ctrl + ⇧Shift + ~) and the installing

pip install pylint_django

solved the problem.

Foad S. Farimani
  • 12,396
  • 15
  • 78
  • 193
0

I had this issue this weekend. It seems to have happened because I opened my project in my venv, but I 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 Visual Studio Code 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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
addohm
  • 2,248
  • 3
  • 14
  • 40
0

I would like to add my trials and my solution following rob3c's answer.

PS: My solution only concerns Windows users.

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 the Python 3 interpreter C:\Python34\python.exe)

And to configure .vscode\settings.json as follows:

// 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

Visual Studio Code uses the Pylint version from my toolchain!

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Sirius
  • 303
  • 2
  • 8
  • It may be effective, but it's a hack. The problem is that VSCode doesn't find pylint even if it's installed and in the `PATH`. I'd rather fix VSCode than work around the problem like this. – Vince Sep 11 '20 at 09:30