Here is how you can solve this issue:
Make sure you selected the right python interpreter for your project (in case you are using virtualenv/pipenv/other):
When you run pipenv shell
, you will see which python interpreter is used. A folder named .vscode
will be created once you select a different interpreter than the default one. Inside .vscode
you will have a settings.json
file.
In settings.json
file you have to add the paths from which you import what's needed in extraPaths
:
{
"python.pythonPath": "/home/youruser/.virtualenvs/app-FzQGSFjf/bin/python",
"python.analysis.extraPaths": ["app", "another/path/etc"]
}
In my case, app
folder was not known by Pylance.
Top comments (14)
In my case, the fastest solution when imports are not missing is to launch vscode from the virtual environment. Basically, activate the venv as always, and then
code .
Thanks for the solution. Just to add, incase of virtual env created from WSL, you need to set the interpreter as shown below.
code.visualstudio.com/docs/python/....
Is there any way to include as a path ALL of the folders below a given path? I'm working inside a folder, with several subfolders, each of them with its own test. This solution solves the problem by adding each individual folder to the extraPaths, every time, but no for a group of folders.
Please comment if you find the solution. I am interested in this too :)
Wild card paths (/) should work something like `folder1/folder2/`
But I am not sure..
I had this issue as well. I selected my Python Interpeter to my conda/mamba environment. But the only thing that worked was Ctrl + Shift + P , Python: Clearing Cache & Reload Workbook
What is the app folder
Adding a note here. You may need to re-select the interpreter after you've run pip to install a new library. Just re-selecting the same thing (instead of changing versions) worked for me. Presumably restarting the app does same thing, but who wants to do that?
Thanks, this makes it easier.
Thanks for the suggestion. Changing the interpreter solved my problem...
wow, just change interpreter from 3.9.5 to 3.9.4, tadaaa... its working now, thank you so much
Thank you very much