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().

@Frederick-Teye
Copy link

Thank you very much. This worked perfectly.

@CorentinJ
Copy link

Appreciated

@leonardozavojanni
Copy link

Thanks

@SamWickershamBryant
Copy link

Exactly what I was looking for. Thank you so much

@goodchong
Copy link

Thanks

@Kile
Copy link

Kile commented Dec 20, 2024

You massive legend, thanks.

What worked for me is using [path you found up to]/site-packages/ to include all packages from my venv

@gavranha
Copy link

Perfect solution. Thank you.

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