I was still getting these errors even after confirming that the correct python
and pylint
were being used from my virtual env.
Eventually I figured out that in Visual Studio Code I was A) opening my project directory, which is B) where my Python virtual environment was, but I was C) running my main Python program from two levels deeper. Those three things need to be in sync for everything to work.
Here's what I would recommend:
In Visual Studio Code, open the directory containing your main Python program. (This may or may not be the top level of the project directory.)
Select Terminal menu > New Terminal, and create an virtual environment directly inside the same directory.
python3 -m venv env
Install pylint in the virtual environment. If you select any Python file in the sidebar, Visual Studio Code will offer to do this for you. Alternatively, source env/bin/activate
then pip install pylint
.
In the blue bottom bar of the editor window, choose the Python interpreter env/bin/python
. Alternatively, go to Settings and set "Python: Python Path." This sets python.pythonPath
in Settings.json.