[Python] Solve Import X could not be resolved in VSCode
Problem
Recently, I have been developing a fastapi project in a virtual environment.
However, when I tried to import modules, I got this error.
Import “X” could not be resolved by Pylance (reportMissingImports)
I found out that this problem was related to a missing additional path where pip
had installed the modules that I wanted to import.
Solution
First, we need to find the location of the imported module:
1 2 3
$ python >>> import modulename >>> print(modulename.__file__)
Open settings in VSCode.
Search pylance.
Find the Extra Paths config item.
Select add item to add a path to the parent folder of the module.
- It won’t do any recursive tree searching.
This post is licensed under CC BY 4.0 by the author.