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 Overflow
Discussions

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
My Flask App server is running but I have three imports that cannot be resolved. I have tried: reinstalling the imports individually reinstalling requirements.txt I configured VSCode Workspace wi... More on stackoverflow.com
🌐 stackoverflow.com
Import "[module]" could not be resolvedPylance (reportMissingImports)
I am learning a Python book, so I created folder for each chapter to storage code. Working directory is as follows: book └─chapter1 ├─a.py ─b.py b.py import a When I "open by code" in "book" folde... More on github.com
🌐 github.com
45
August 13, 2020
Import could not be resolved in VS Code
I am trying to write a code in Azure Functions through VS Code, but in import it says "Import could not be resolved". Following is screenshot Python is installed, Azure Storage Account is installed Do I need to put them in some… More on learn.microsoft.com
🌐 learn.microsoft.com
1
0
November 17, 2022
Visual Studio 2022 import xyz could not be resolved from the source
I upgraded Visual Studio 2022 Enterprise version 17.4.4 I loaded the python project previously configured by Visual Studio 2019. Visual Studio 2022 keeps complaining about Python libraries set up in virtual environment. The virtual environment was… More on learn.microsoft.com
🌐 learn.microsoft.com
0
0
March 20, 2023
🌐
GitHub
gist.github.com › krisbolton › 20159d66f1d919c9c2380c96b6ac3915
VSCode import could not be resolved by Pylance (reportMissingImports) · GitHub
Pylance now knows where to find the module you were attempting to import. N.b. you can exit the python interpreter by typing exit(). ... Thank you very much. This worked perfectly. ... Exactly what I was looking for. Thank you so much ... You massive legend, thanks. What worked for me is using [path you found up to]/site-packages/ to include all packages from my venv
🌐
Bobby Hadz
bobbyhadz.com › blog › python-import-could-not-be-resolved-from-source-pylance-reportmissingmodulesource
Import "X" could not be resolved from source Pylance [Fixed] | bobbyhadz
April 10, 2024 - The error "Import "X" could not be resolved from source Pylance" occurs when the imported module is not installed or you have selected the incorrect Python interpreter in your IDE (e.g.
🌐
GitHub
github.com › microsoft › pylance-release › issues › 236
Import "[module]" could not be resolvedPylance (reportMissingImports) · Issue #236 · microsoft/pylance-release
August 13, 2020 - Import "[module]" could not be resolvedPylance (reportMissingImports)#236 · Copy link · Labels · waiting for user responseRequires more information from userRequires more information from user · jiangzhuochi · opened · on Aug 13, 2020 · Issue body actions ·
Author   jiangzhuochi
🌐
Microsoft Learn
learn.microsoft.com › en-us › answers › questions › 1093387 › import-could-not-be-resolved-in-vs-code
Import could not be resolved in VS Code - Microsoft Q&A
November 17, 2022 - @Krishnamohan Nadimpalli Thanks for reaching out. For your first issue Import could not be resolved in VS Code for pandas it will resolve once the panda is installed on your function environment locally.
Find elsewhere
🌐
Microsoft Learn
learn.microsoft.com › en-us › answers › questions › 1191390 › visual-studio-2022-import-xyz-could-not-be-resolve
Visual Studio 2022 import xyz could not be resolved from the source - Microsoft Q&A
March 20, 2023 - Visual Studio 2022 keeps complaining about Python libraries set up in virtual environment. The virtual environment was configured in Visual Studio 2019 and works in Visual Studio 2019 perfectly. In general, Visual Studio 2022 says import xyz could not be resolved from the source, where xyz could be library such as pandas or sqlarchemy
🌐
Sentry
sentry.io › sentry answers › vs code › fix pylance resolvemissingimports in vs code
Fix Pylance resolveMissingImports in VS Code | Sentry
July 15, 2024 - Select the Python interpreter in your virtual environment – it should be the top option, with a “Recommended” tag. If you previously installed fastapi to the virtual environment, the resolveMissingImports error should now disappear.
🌐
Python.org
discuss.python.org › python help
How does one fix an import error like the following? - Python Help - Discussions on Python.org
November 24, 2023 - This code: from azure.cognitiveservices.vision.customvision.training import CustomVisionTrainingClient from azure.cognitiveservices.vision.customvision.training.models import ImageFileCreateBatch, ImageFileCreateEntry, Region from msrest.authentication import ApiKeyCredentials import time import os def main(): from dotenv import load_dotenv global training_client global custom_vision_project Errors generated: "message": "Import \"azure.cognitiveservices.vision.customvision.traini...
🌐
GitHub
github.com › microsoft › pylance-release › issues › 3035
"Import could not be resolved" for local packages and modules · Issue #3035 · microsoft/pylance-release
July 8, 2022 - To read more about this, see https://github.com/ipython/ipython/issues/2049 To connect another client to this kernel, use: --existing c:\Users\dariush\AppData\Roaming\jupyter\runtime\kernel-v2-16040HnxfnN5XtDwc.json info 17:35:43.32: Started kernel myenv (Python 3.10.5)., (Raw session started and connected) info 17:35:43.33: Finished connecting 77698eb3-0340-4306-ac43-d152a89a6550 info 17:35:43.34: UpdateWorkingDirectoryAndPath in Kernel info 17:35:43.34: Executing silently Code (idle) = import os\nimport sys\n� "d:\projects\bugs"\nif os.getcwd() not in sys.path:\nsys.path.insert(0, o info 1
Author   dariush-bahrami
🌐
GitHub
github.com › microsoft › vscode › issues › 151832
Import module could not be resolved from source · Issue #151832 · microsoft/vscode
June 11, 2022 - Issue Type: Bug 1- I installed the module "requests" using the command "pip install requests" and checked that it is indeed exist on my machine using the command "pip list". 2- I wrote a python file that contains the line "import request...
Author   Mopro007
🌐
Code with Mosh
forum.codewithmosh.com › python
Import could not be resolved - Python - Code with Mosh Forum
June 21, 2021 - Hi Guys, I am beginner in Python, but I have problems when I try to import libraries, so maybe I have problems with the extension That I had activated.
🌐
GitHub
github.com › microsoft › pylance-release › issues › 2288
Import could not be resolved problem in vscode pylance v2022.1.3 · Issue #2288 · microsoft/pylance-release
January 26, 2022 - Pylance extension in VSCode (running on Win10-64) reports problem: Import "requests.packages.urllib3.exceptions" could not be resolved from source · Although requests package is properly installed and the import is valid.
Author   shaishap
Top answer
1 of 7
73

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:

  1. Open settings (ctrl + ,)
  2. Search "pylance" or find it under "Extensions > Pylance"
  3. Find the "Extra Paths" config item
  4. 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.

2 of 7
24

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 .vscode at 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.json and 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.json file.

I hope this helps.

🌐
Medium
medium.com › @littechie › troubleshooting-import-module-error-in-python-a-solution-that-worked-901e2e2efb1b
Troubleshooting “Import Module” Error in Python: A Solution That Worked | by Lit Techie | Medium
July 26, 2023 - By creating a fresh virtual environment and reinstalling the required dependencies, I successfully resolved the “Import ‘module’ could not be resolved from source PylancereportMissingModuleSource” error that was preventing me from importing the “redis” module in my FastAPI project.
🌐
GitHub
github.com › microsoft › pylance-release › issues › 207
Import "django.urls" could not be resolved from sourcePylance (reportMissingModuleSource) · Issue #207 · microsoft/pylance-release
August 7, 2020 - Import "django.urls" could not be resolved from sourcePylance (reportMissingModuleSource)#207 · Copy link · Labels · waiting for user responseRequires more information from userRequires more information from user · asimnp · opened · on Aug 7, 2020 · Issue body actions ·
Author   asimnp