Pylint “unresolved import” error in Visual Studio Code

I am using the following setup

  • macOS v10.14 (Mojave)
  • Python 3.7.1
  • Visual Studio Code 1.30
  • Pylint 2.2.2
  • Django 2.1.4

I want to use linting to make my life a bit easier in Visual Studio Code. However, for every import I have states “unresolved import”. Even on default Django imports (i.e. from django.db import models).

I presume it is because it is not seeing the virtual environment Python files.

Everything works just fine, but it’s starting to get annoying.

The interpreter choices I have are all system versions of Python. It does not seem to see my virtual environment Python at all (it is not in the same directory as my workspace, so that part makes sense).

If I set up the python.PythonPath in the settings.json file, it just ignores it and does not list my virtual environment path as an option. I also tried setting it up in my global Python settings, but it also does not show up.

Is there a quick fix to get it working?

41 Answers
41

The accepted answer won’t fix the error when importing own modules.

Use the following setting in your workspace settings .vscode/settings.json:

"python.autoComplete.extraPaths": ["./path-to-your-code"],

Reference: Troubleshooting, Unresolved import warnings

Leave a Comment