10

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?

Krishna Moniz
  • 498
  • 1
  • 6
  • 11

3 Answers3

17
  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

Pieter
  • 895
  • 11
  • 22
Bill
  • 194
  • 1
  • 8
  • I found out visual studio already tell us how to change python here: https://code.visualstudio.com/docs/python/python-tutorial, it's almost like my answer, but provide another way: Select Interpreter command on the Command Palette (⇧⌘P) – Bill Mar 30 '18 at 16:07
  • I Also found vsc if you choose python3 as default interpreter, then create a new xx.python, it will show a prompt box to guide u to install pylint, when you choose to install it will execute shell command in terminal: `$ /usr/local/bin/python3 -m pip install -U pylint --userCollecting pylint` – Bill Mar 30 '18 at 22:57
  • So simple! yet so hard to locate. Thanks a lot! – RicardoE Aug 25 '18 at 05:55
5

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

sudo python3 -m pip install -U pylint

enter image description here

Krishna Moniz
  • 498
  • 1
  • 6
  • 11
0
  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.