Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save krisbolton/20159d66f1d919c9c2380c96b6ac3915 to your computer and use it in GitHub Desktop.
Save krisbolton/20159d66f1d919c9c2380c96b6ac3915 to your computer and use it in GitHub Desktop.
VSCode import could not be resolved by Pylance (reportMissingImports)

Problem

Visual Studio Code (VSCode) reports an error (yellow squiggly lines) saying "Import [nameOfModule] could not be resolved by Pylance (reportMissingImports)". You may be using a virtual environment (e.g., venv).

Solution

You need to tell Pylance where pip has installed the module you are trying to import. This is called an "additional path".

  1. Find the location of the module. In the VSCode terminal within your project enter the python interpreter by typing python.
  2. Once the interpreter is active (shown by >>> instead of $ or %) type import [nameOfModule] and press enter.
  3. Type print([nameOfModule].__file__) to print the path location of the module.
  4. In VSCode open settings by pressing ctrl + , and a search box will appear.
  5. Search for and select "pylance".
  6. Find the "Extra paths" item.
  7. Press the "add item" button and copy & paste the path you found in step 3.

The squiggly lines and the error should have gone. Pylance now knows where to find the module you were attempting to import.

N.b. you can exit the python interpreter by typing exit().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment