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

Error Unable to import 'fastapi' en Visual Code
First Check I added a very descriptive title here. I used the GitHub search to find a similar question and didn't find it. I searched the FastAPI documentation, with the integrated search. I al... More on github.com
🌐 github.com
2
1
Frequent 'pylance' Questions - Stack Overflow
Stack Overflow | The World’s Largest Online Community for Developers 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
Import could not be resolved [Pylance]
Try to Reload Window. If the error still exists, check if you install the module in your selected interpreter environment. More on reddit.com
🌐 r/vscode
12
14
June 23, 2021
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.

🌐
Stack Overflow
stackoverflow.com › questions › tagged › pylance
Frequent 'pylance' Questions - Stack Overflow
Hi I am getting the following warning (A squiggly line underneath imports), import "numpy" could not be resolved Pylance(reportMissingModuleSource).
🌐
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 ...
Find elsewhere
🌐
GitHub
github.com › microsoft › pylance-release › issues › 4606
Pylance seems to forget the selected interpreter after a (short) while: reportMissingImports · Issue #4606 · microsoft/pylance-release
July 14, 2023 - After some editing, lots of problems are shown because the imports could not be resolved. ... However, Pylance trace output shows that (at least part of) Pylance is still using the standard interpreter of Ubuntu.
Author   microsoft
🌐
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 - Whenever I install a package or add, change the name of a file in the project directory pylance does not update. It show import error and autocompletion and intellisense does not work.
Author   microsoft
🌐
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
🌐
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

🌐
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 - Here is how you can solve this issue: Make sure you selected the right python interpreter for your...
🌐
The Fish Shell
mvolkmann.github.io › blog › python › python-compared-to-js
Python compared to JavaScript
Install the required dependencies by entering pip install fastapi pydantic uvicorn.
🌐
Reddit
reddit.com › r/learnpython › having problems, specifically with imports not resolved.
r/learnpython on Reddit: Having problems, specifically with imports not resolved.
December 27, 2024 -

They are called Pip’s I believe. Not totally sure if I need to download them to my computer or if I can copy and paste the Bash into the line of code. I created the program with the help of YouTube but unfortunately I can’t find a video that helps with this problem. Been working at it for a few days now with no resolution lol so anything helps, thanks

🌐
DEV Community
dev.to › drsimplegraffiti › fast-api-part-1--j2l
Fast Api [part 1 ] - DEV Community
March 31, 2022 - from fastapi import FastAPI from pydantic import BaseModel app = FastAPI() cars = { 1:{"model": "Volvo", "year": 2021, "new": True}, 2:{"model": "Benz", "year":2020}, 3:{"model": "Toyota", "year": 1999}, } @app.get("/cars") async def show_cars(): return cars
🌐
Stack Overflow
stackoverflow.com › questions › tagged › pylance
Highest scored 'pylance' questions - Stack Overflow
When running ipynbs in VS Code, I've started noticing Pylance warnings on standard library imports. I am using a conda virtual environment, and I believe the warning is related to that. An example ... ... whenever I try to import matplotlib or matplotlib.pyplot in VS Code I get the error in the title: Import "matplotlib" could not be resolved from source Pylance(reportMissingModuleSource) or ...
🌐
Bobby Hadz
bobbyhadz.com › blog › python-no-module-named-fastapi
ModuleNotFoundError: No module named 'fastapi' in Python | bobbyhadz
April 10, 2024 - To solve the error, install the module by running the pip install fastapi command. Open your terminal in your project's root directory and install the fastapi module. ... Copied!# 👇️ In a virtual environment or using Python 2 pip install ...
🌐
GitHub
github.com › microsoft › pylance-release › issues › 774
The auto-import logic is not picking the shortest import path for symbols · Issue #774 · microsoft/pylance-release
December 26, 2020 - I recently released FastAPI 0.63.0 with support for mypy --strict, including re-exports in the source files for the symbols I want re-exported.
Author   microsoft