The causes could be:

  1. The name of the file - fastapi.py, if you name it in this could way you would get import errors. (Avoid filenames similar to package names)
  2. Installing on other environments. Most of the time it happens when you use both Conda and PiP on you system.
  3. If you run the code from VS Code, check if the same interpreter is selected.

Verify the installation:

$ pip list | grep fastapi

Suggestions:

OPT Virtual Environments to avoid these troubles.

Thank you!

Answer from Mahimai Raja J on Stack Overflow
🌐
Sentry
sentry.io › sentry answers › vs code › fix pylance resolvemissingimports in vs code
Fix Pylance resolveMissingImports in VS Code | Sentry
July 15, 2024 - If you previously installed fastapi to the virtual environment, the resolveMissingImports error should now disappear.
Discussions

Problem with FastAPI and VSCODE
Try "from fastapi import FastAPI". Then you can do something like "app = FastAPI()" More on reddit.com
🌐 r/FastAPI
20
1
October 28, 2025
Frequent 'pylance' Questions - Stack Overflow
Stack Overflow | The World’s Largest Online Community for Developers More on stackoverflow.com
🌐 stackoverflow.com
python - how do I solve the Pylance(reportMissingImports)? - Stack Overflow
I used pip install fastapi to download it in my virtual environment, in terminal but when I try to import from it it shows up as a missing import. More on stackoverflow.com
🌐 stackoverflow.com
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
🌐
Reddit
reddit.com › r/fastapi › problem with fastapi and vscode
r/FastAPI on Reddit: Problem with FastAPI and VSCODE
October 28, 2025 -

Hi everyone, im trying to learn FastAPI in school but when I try using "import FastAPI from fastapi" in the beggining of the code, it gives me an error as if I didnt have it downloaded. Can someone help? I already have all this extensions downloaded and im using a WSL terminal on Visual Studio Code.

annotated-doc==0.0.3

annotated-types==0.7.0

anyio==4.11.0

certifi==2025.10.5

click==8.3.0

dnspython==2.8.0

email-validator==2.3.0

fastapi==0.120.1

h11==0.16.0

httpcore==1.0.9

httptools==0.7.1

idna==3.11

Jinja2==3.1.6

markdown-it-py==4.0.0

MarkupSafe==3.0.3

mdurl==0.1.2

numpy==2.3.4

pyarrow==22.0.0

pydantic==2.12.3

pydantic_core==2.41.4

Pygments==2.19.2

pylance==0.38.3

python-dotenv==1.2.1

python-multipart==0.0.20

PyYAML==6.0.3

rignore==0.7.1

sentry-sdk==2.42.1

shellingham==1.5.4

sniffio==1.3.1

starlette==0.49.0

typing-inspection==0.4.2

typing_extensions==4.15.0

urllib3==2.5.0

uvicorn==0.38.0

uvloop==0.22.1

watchfiles==1.1.1

websockets==15.0.1

🌐
Stack Overflow
stackoverflow.com › questions › tagged › pylance
Frequent 'pylance' Questions - Stack Overflow
I have tried: reinstalling the imports individually reinstalling requirements.txt I configured VSCode Workspace with ... ... It is a similar situation I'd encountered several months ago using pylint prior to pylance: My python 3.9x - script (using VS Code on Ubuntu 20.04 LTS) starts with the following import of custom "... ... When I am writing from flask import Flask One Yellow line is coming up under flask and stating Import "flask" could not be resolved from source Pylance (reportMissingModuleSource) .
Top answer
1 of 2
31

If you want to install a package into your specific virtual environment, you need to first "activate" that environment. Likewise, if you want to run your script in that environment, you need to first "activate" it. You can do this manually or preferably let VSCode handle it for you.

In order to tell VSCode(especially the language server which is pylance) to use that environment:

  1. Open up your Command Palette(press ctrl+shift+P or f1) and type : "python: select interpreter".
  2. Browse/Select your newly created python interpreter's path inside your venv.
  3. Add "python.terminal.activateEnvironment": true to your setting.json file(It's also possible via GUI setting of course by searching for python: activate environment). This will automatically detect and activate your venv whenever you open your integrated terminal. Obviously If the path should points to a venv interpreter. (Note: you have to have a Python file opened in your editor).

You can also set your Python's interpreter path manually:

  1. Create a folder called .vscode in your workspace.
  2. Create a file called settings.json inside it.
  3. Add these to settings.json:
{
    "python.defaultInterpreterPath": "PATH_TO_VENV_INTERPRETER",
    "python.terminal.activateEnvironment": true
}

Note: What I normally do is, I insert a "python.defaultInterpreterPath" key to my User settings.json which points to my global interpreter. Then I create Workspace settings.json for each of my projects and add the same key which points to my venv's interpreter. Remember, workspace settings.json will overwrite user's settings.json.

This way whenever you open VSCode in a project folder it automatically knows it should activate your venv's interpreter(I told it to do so with "python.terminal.activateEnvironment") and if you open VSCode in a normal folder it correctly use your global's interpreter.

Difference between User and Workspace settings.json.

2 of 2
6

Please select the appropriate interpreter for your running environment.

ctrl+shift+P

and then choose the one like picture.

Find elsewhere
🌐
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 ...
🌐
GitHub
github.com › zed-industries › zed › discussions › 32362
Python imports don't work in virtual enviroments · zed-industries/zed · Discussion #32362
I am working on a project in a venv, and am importing fastapi. In VSCode, everything works fine, but in Zed I was getting the error Import "fastapi" could not be resolved (Pyright reportMissingImports). I Googled it, and found that I needed to configure Pyright settings.
Author   zed-industries
🌐
GitHub
github.com › microsoft › pylance-release › issues › 1443
Pylance does not update on adding new files and packages · Issue #1443 · microsoft/pylance-release
June 13, 2021 - It show import error and autocompletion and intellisense does not work. I have to reload the entire windows for pylance to recognise the file or package ... just after installing xknx using: sudo pip3 install xknx pylance shows error and does not gives intellisence or autocomplete I have to restart vscode to get it to work
Author   microsoft
🌐
DEV Community
dev.to › climentea › how-to-solve-pylance-missing-imports-in-vscode-359b
How to solve Pylance 'missing imports' in vscode - DEV Community
February 3, 2021 - In my case, the fastest solution when imports are not missing is to launch vscode from the virtual environment.
🌐
Reddit
reddit.com › r/fastapi › forever having trouble in vs code
r/FastAPI on Reddit: Forever having trouble in VS Code
January 19, 2024 -

No matter how many times I verify it, I always get the Module not found error. I've confirmed fastapi install and version with pip freeze. I have 0.109.0 installed. The interpretter is the same as the python/python3 --version. I've checked all the which python/python3 and they lead to same path. Any help is greatly appreciated. TIA.

🌐
DEV Community
dev.to › drsimplegraffiti › fast-api-part-1--j2l
Fast Api [part 1 ] - DEV Community
March 31, 2022 - from fastapi import FastAPI app = FastAPI() @app.get("/") async def root(): return {"message": "Hello World"} The above is the most basic version of our restapi. We now have a problem because we use vscode and our Python interpreter cannot be found.
🌐
Reddit
reddit.com › r/learnpython › vscode saying import could not be resolved but it definitely is
r/learnpython on Reddit: vscode saying import could not be resolved but it definitely is
July 9, 2021 -

I'm getting this weird thing in vscode where my import is working properly but theres a yellow line under the module name and when I hover over that, it says module can't be resolved.

If I try and change how I access the module (using a relative path, perhaps), the yellow error line is no longer there but the code doesn't work as python or vscode doesn't recognise the module name/path

Does anyone have experience with this?

My code works but the yellow line is annoying.

I don't NEED to separate my code into different files but it would still be good to know what's going on here

Thank you

🌐
YouTube
youtube.com › programmingknowledge2
How To Fix Import Could Not Be Resolved From Source Pylance - YouTube
Welcome to this tutorial on how to fix "Import could not be resolved from source" Pylance error.Pylance is a powerful language server that provides advanced ...
Published   May 15, 2023
Views   43K
🌐
GitHub
github.com › microsoft › pylance-release › issues › 236
Import "[module]" could not be resolvedPylance (reportMissingImports) · Issue #236 · microsoft/pylance-release
August 13, 2020 - 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" folder, the Yellow wavy line is below the cod...
Author   microsoft
🌐
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 - 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…
🌐
GitHub
github.com › microsoft › pylance-release › issues › 2478
Import x could not be resolvedPylancereportMissingImports - wsl + asdf-vm · Issue #2478 · microsoft/pylance-release
March 16, 2022 - Environment data Language Server version: v2022.3.1 OS and version: WSL: Arch Python version (& distribution if applicable, e.g. Anaconda): 3.10.2 using asdf-vm Expected behaviour Import packag...
Author   microsoft
🌐
GitHub
gist.github.com › krisbolton › 20159d66f1d919c9c2380c96b6ac3915
VSCode import could not be resolved by Pylance (reportMissingImports) · GitHub
Find the location of the module. In the VSCode terminal within your project enter the python interpreter by typing python.