On my computer I have 3 Pythons, a 3.6 from Anaconda, and a 2.7 & 3.7 that are regular python. Prompted by a nudge from this GH issue, I switched from the Anaconda 3.6 to the 3.7, and back again, and the problem went away.

I think that this is the case because your .vscode/settings.json (the following is mine), doesn't have that last line until you change your python, at which point, that last line is put in and Pyright has something to look at.
{
"python.linting.enabled": true,
"python.formatting.provider": "black",
"python.pythonPath": "C:\\Users\\ben\\Anaconda3\\python.exe"
}
Answer from Ben on Stack OverflowOn my computer I have 3 Pythons, a 3.6 from Anaconda, and a 2.7 & 3.7 that are regular python. Prompted by a nudge from this GH issue, I switched from the Anaconda 3.6 to the 3.7, and back again, and the problem went away.

I think that this is the case because your .vscode/settings.json (the following is mine), doesn't have that last line until you change your python, at which point, that last line is put in and Pyright has something to look at.
{
"python.linting.enabled": true,
"python.formatting.provider": "black",
"python.pythonPath": "C:\\Users\\ben\\Anaconda3\\python.exe"
}
python -m pip install -U pylint
python -m pip install --upgrade pip
Open VS Code -> CTRL + SHIFT P -> Search 'select linter' [Python: Select Linter] -> Hit Enter and Select Pylint
If not solved.
Try deactivate your environment pip install numpy in your global environment.
And if you are using Local Environment getting unresolved imports error then add In .vscode/settings.json "python.analysis.extraPaths": ["./path-to-your-code"], for example "python.analysis.extraPaths": [ "*.lib" ]
I'm trying to use torch in a python script but even though it's pip installed, pylance doesn't recognize it
https://imgur.com/EM5fEIo
Any advice on how to resolve this? Thanks.
flask - Import could not be resolved/could not be resolved from source Pylance in VS Code using Python 3.9.2 on Windows 10 - Stack Overflow
Import "[module]" could not be resolvedPylance (reportMissingImports)
Import could not be resolved in VS Code
Visual Studio 2022 import xyz could not be resolved from the source
Videos
Open the Command Palette (Ctrl+Shift+P), then select the Python: Select Interpreter. From the list, select the virtual environment in your project folder that starts with
.env.Run Terminal: Create New Integrated Terminal (Ctrl+Shift+` or from the Command Palette), which creates a terminal and automatically activates the virtual environment by running its activation script.
Install
sqlalchemyandmongoenginewith commandpip install. Once installing them successfully, there will intellisense when you import them and no warnings shown.

Besides, the folder .vscode is to store Workspace settings as well as debugging and task configurations.
To resolve the issue, perform the following steps:
- Open the Command Palette by pressing Ctrl+Shift+P on your keyboard.
- In the Command Palette, select Python: Clear Cache and Reload Window.
The issue was indeed with Pylance. It was missing an "additional path" to where pip had installed the projects I wanted to import. To solve the issue:
First make sure you know the location of your import; you can find it with:
$ python
>>> import modulename
>>> print(modulename.__file__)
Then, once you know the location:
- Open settings (ctrl + ,)
- Search "pylance" or find it under "Extensions > Pylance"
- Find the "Extra Paths" config item
- Use "add item" to a add a path to the parent folder of the module. It will not do any recursive tree searching
And you should be good to go!
For a further example, you can see the image above where I had added the path /home/seph/.local/lib/python2.7/ to no avail. Updating it to /home/seph/.local/lib/python2.7/site-packages/ did the trick.
I had a similar problem in my setup as I create a virtual environment per project and install Jupyter there. Instead of a global setting change in the Pylance extension, I rather prefer to follow what states its troubleshooting guide.
Suppose your virtual environment is called venv and it is inside your project folder:
- Create a folder called
.vscodeat the root of your project folder, if it does not already exist. Don't forget the dot in front of the name. - Create or edit the file
.vscode/settings.jsonand include this tag:
{
"python.analysis.extraPaths": ["./venv"]
}
- Note that the path to your virtual environment is relative to the root project folder, not the folder containing the
settings.jsonfile.
I hope this helps.
Try cleaning your project by going to the following menu item:
Project > Clean...
If that doesn't work, try removing the jars from the build path and adding them again.
Obviously there are cases where there is a valid issue however Eclipse throws this error for no good reason sometimes. This is still (in v 2020-09) an old (2010) Eclipse bug that can be resolved by making a negligible change to the project settings.
touch .classpath
solves the issue, or go to Project > Properties > Java Build Path > Order and Export > make a meaningless order change > Apply. Changing the order back does not regress to the problem.