Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure pylint for both python2 and python3 in vs code

I have two projects in two windows , one in python2 and other in python3.

Is there anyway I can use both pylint for python2 and python3 in vscode for different projects on the fly ?

I tried, but I can't use both of them. Either I can able to set python2 pylint or the python3 one.

like image 929
jeyanthinath Avatar asked May 24 '17 06:05

jeyanthinath


1 Answers

Yes, there is a way.

You can set one interpreter for each folder (project) you have open in vscode. And this will dictate the linting (asuming you have the modules installed for each interpreter). This way you can have two different projects open at the same time and each will use their set interpreter and lintern.

  • The automatic way
    The ideal way to select the interpreter for your current project-folder is to open the command palette (F1) and type "Python: Select Workspace Interpreter" and choose from the dropdown list (all while you have your project open). And that's it. Vscode will use that interpreter and lintern.

  • The manual way
    Now, if when you try to select an interpreter like I described above you get a message like this: "There are no entries to select from" even though you have both interpreters installed, like it happened to me (when I tried on Windows, I think maybe because of the Python Launcher for Windows). You can still select the interpreter. You're just going to have to do it manually.
    While you have your project open, on de command palette write "Preferences: Open Workspace Settings" and hit enter. This will create and open an empty settings.json file in a hidden .vscode folder inside your project folder. In this file you can set the exact python interpreter you want to use in the project. For example, for python 2, like this:
    "python.pythonPath": "C:\\Python27\\python.exe"
    With that you should be able to lint and debug with an specific interpreter.

like image 88
Daniel F. Avatar answered Sep 19 '22 00:09

Daniel F.