Krishna Moniz
Krishna Moniz

Reputation: 508

How can I get pylint to use python 3 in VS code?

I want pylint to use python3 for linting in Visual Studio code on Mac (which has both python 2.7 standard and python 3.6).

I've tried changing the path to the python interpreter as per How can I debug Python3 code in Visual Studio Code, to no avail. I keep getting python2 errors instead of python3 errors.

See example code for the problem.

Is there a way I can get pylint to recognize python3 errors?

Upvotes: 10

Views: 11373

Answers (3)

Hossam26644
Hossam26644

Reputation: 54

  1. The simple solution is to just change the first line of the file /home/user_name/.local/bin/pylint from #!/usr/bin/python2 to #!/usr/bin/python3

  2. If you want more, you can rename this file to pylint2 and have a copy pylint3 where you change the first line to #!/usr/bin/python3.

    Now to use pylint3 from command line you just need to type pylint3 instead of pylint.. also change the directory of pylinter in vscode to /home/user_name/.local/bin/pylint3

explanation

Ok this might be very late and the answer might not be the optimum, but I had the same issue.

By default the path to pylint is /home/user_name/.local/bin/pylint that is a simple python script working as the entry point to pylint.. even after installing pylint using pip3 this file is not changed and keeps directing to use python2 and therefore the packages installed by pip2 for python2.

So either have separate entry points for each pylint version, or modify this one manually to use the pylint package installed for python3.

Upvotes: 0

Krishna Moniz
Krishna Moniz

Reputation: 508

I finally got it working by installing python3 pylint from the console.

sudo python3 -m pip install -U pylint

enter image description here

Upvotes: 5

Bill
Bill

Reputation: 204

  1. Pick a xx.py in Visual Studio Coce(VSC)
  2. In Status Bar Tap Python 2.7.10 like the [img1]
  3. Choose python 3.x like [img2]
  4. Command+Q quit VSC, then open VSC again

enter image description here

img2

Upvotes: 18

Related Questions