21

I can't get pylint errors to show up in VSCode. I installed pylint globally (sudo apt install pylint), I created venv and installed it there with pip, I selected pylint as linter in VSCode, enabled it, ran it, and it doesnt show any errors in my file. If I check from the command line, it shows many errors in my file.

This was working earlier, but not now on VSCode version 1.46.1 and 1.45.1 installed using snap.

Same results with the Microsoft and the Jedi python language server.

I found the pylint command in the developer console:

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

So pylint is indeed executed! If I run it like this from the command line, the output is:

Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)

But if I execute pylint micro.py I get:

Your code has been rated at -2.50/10 (previous run: 10.00/10, -12.50)

Why is VSCode using that command line? I am testing now without a .pylintrc, but even when I had it, VSCode showed no errors, only the command line! However I just tried it again, added a .pylintrc and now the errors do show up in the editor for some reason!

But this is only with the Jedi server, when trying with the Microsoft server, linting cannot be enabled with its command, nothing happens and it stays off.

My .vscode/settings.json:

{
    "python.linting.pylintEnabled": true,
    "python.linting.enabled": true,
    "python.linting.pylintArgs": [
        "--rcfile",
        "${workspaceFolder}/backend/.pylintrc"
    ]
}
Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
atlau
  • 881
  • 1
  • 7
  • 16
  • 3
    Have you tried to do `ctrl+shift+p` i guess `cmd+shift+p` on Mac and then write `select linter`. It should display you a list of the linter installed, if `pylint` is not installed you can do it with pip `pip install pylint` or conda `conda install -c anaconda pylint` – PasNinii Jun 19 '20 at 15:15
  • I used the commands already: select linter, enable linter, run linter, and nothing happens. – atlau Jun 19 '20 at 15:19
  • 1
    Have you checked your settings like the `ctrl+shift+p` settings both (json) and (ui) and see there if everything is configured normally – PasNinii Jun 19 '20 at 15:21
  • you can try to add `"python.linting.pylintEnabled": true` in your `settings.json` file – PasNinii Jun 19 '20 at 15:22
  • Yes I have that in settings.json, and "python.linting.pylintEnabled": true, – atlau Jun 19 '20 at 15:55
  • So have you tried my method? – Angus Jun 21 '20 at 06:26
  • Please share your settings for VS Code related to Pylint. – Brett Cannon Jun 22 '20 at 20:53
  • It seems pylint is not executed and no error is reported when pylintrc is not found, for example due to wrong --rcfile path. – atlau Jan 05 '21 at 17:41
  • This might've been a configuration issue or bug. Right now using Pylance language server Pylint works fine. – atlau Apr 25 '22 at 14:37

6 Answers6

24

Simplest way using UI:

  1. Press "Ctrl + Shift + P" to get Command Palette
  2. Type "Lint"

enter image description here

  1. Select "Python : Enable/Disable Linting", click on "Enable"
  2. Repeat Step 1 & 2, now select "Python : Select Linter", Select pylint from options

enter image description here

  1. Above steps will add below lines in "settings.json" under .vscode dir

enter image description here

Tarun Kumar
  • 729
  • 1
  • 8
  • 16
  • 3
    I dont have the `Lint` option, nor `Python: Select Linter` as it says [here](https://code.visualstudio.com/docs/python/linting) any idea why? – J Agustin Barrachina Feb 10 '23 at 09:29
  • 3
    Make sure you have python extension installed in VS Code. Link : https://marketplace.visualstudio.com/items?itemName=ms-python.python – Tarun Kumar Feb 16 '23 at 06:28
  • 1
    Also check at the right bottom of VS code if the right python interpreter version is selected (in case if you have multiple versions installed) – Tarun Kumar Feb 16 '23 at 06:29
  • If you're not seeing the linting lines in the settings.json, recall VS-Code has several settings (User, Remote, Workspace). So make sure you're looking at the correct settings.json (i.e. either User, Remote, or Workspace). – user3731622 Mar 15 '23 at 18:58
  • I also don't have `Lint` option available in the command Pallete. – vasu Jun 30 '23 at 14:25
7

As this post suggests, this is currently fixed: https://github.com/microsoft/vscode-python/issues/12285#issuecomment-649350148

My .vscode/settings.json:

{
    "python.linting.enabled": true,
    "python.linting.pylintEnabled": true,
    "python.languageServer": "Microsoft"
}

It should work both on Jedi and Microsoft servers. Cheers!

Yan Tavares
  • 191
  • 1
  • 8
6

As of March 2022, VS Code team developed a new Pylint extension. You can directly install and use it. https://marketplace.visualstudio.com/items?itemName=ms-python.pylint

Emre
  • 933
  • 15
  • 27
1

I just installed Pylint extension to VSCode as shown below. *I use Anaconda on Windows 11:

enter image description here

Then, it works properly as shown below:

enter image description here

Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
0

I had the same issue, but resolved it after installing the cornflakes-linter for VS code.

pseudomarvin
  • 1,477
  • 2
  • 17
  • 32
-2

Perhaps one possible solution could be launching the VS Code from the terminal/cmd.

These are the steps to enable you to launch the VS Code from the terminal (macOS), from the VS code site.

For installation:

  1. Download Visual Studio Code for macOS.
  2. Open the browser's download list and locate the downloaded archive.
  3. Select the 'magnifying glass' icon to open the archive in Finder.
  4. Drag Visual Studio Code.app to the Applications folder, making it available in the macOS Launchpad.
  5. Add VS Code to your Dock by right-clicking on the icon to bring up the context menu and choosing Options, Keep in Dock.

Launching from the command line:

  1. Launch VS Code.
  2. Open the Command Palette (⇧⌘P) and type shell command to find the Shell Command: Install 'code' command in PATH command.
  3. Restart the terminal for the new $PATH value to take effect. You'll be able to type code . in any folder to start editing files in that folder.

Launching the VS Code from the command line in venv:

  1. Activating venv in your terminal/command line, for my case, I use source activate venv
  2. Launch VS Code after the activation of venv, using code . in the desired directory.

For Windows and Linux, the steps to set up the path can be found in the links.

Angus
  • 3,680
  • 1
  • 12
  • 27