HuLu ViCa
HuLu ViCa

Reputation: 5456

pylint marks error with all imports for libraries installed

I am using pylint with Visual Studio Code, and it works fine, with the exception that it marks error in all import clauses that are not modules from python or from my project. It marks error with imports from Django, Django Rest Framework, etc.

enter image description here enter image description here

How can I configure pylint to recognize these libraries that are installed and working (I don't get any error from python)?

Upvotes: 0

Views: 512

Answers (1)

Gino Mempin
Gino Mempin

Reputation: 29719

You need to set the correct Python interpreter.
See the VS Code docs > Select and activate an environment.

Basically:

  1. Open the Command Palette (Ctrl+Shift+P or +Shift+ P)
  2. Enter "Python: Select Interpreter"
  3. Select the Python environment where both Django and pylint is installed
  4. Reopen the file

You can confirm the current environment selected from the status bar.

enter image description here

You can also check it from the workspace's settings.json, where a python.pythonPath settings gets automatically added/updated every time you switch environments:

{
    "python.pythonPath": "/Users/gino/.venvs/test-django/bin/python",
    ...
}

Pylint basically checks the currently activated environment for import errors.

If the errors does not instantly disappear, try reloading VS Code.

Upvotes: 1

Related Questions