0

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)?

HuLu ViCa
  • 5,077
  • 10
  • 43
  • 93

1 Answers1

1

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.

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135