Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ModuleNotFoundError: No module named 'fastapi'

Here is my file structure and requirements.txt:

Here is my file structure and requirements.txt

Getting ModuleNotFoundError, any help will be appreciated.

main.py

from fastapi import FastAPI
from .import models
from .database import engine
from .routers import ratings


models.Base.metadata.create_all(bind=engine)


app = FastAPI()


app.include_router(ratings.router)

like image 646
Zurab Skhiladze Avatar asked Nov 19 '25 16:11

Zurab Skhiladze


2 Answers

The error comes from the fact that you were not using the right environment and python version on VSCODE. Your environment knew your different packages, but VSCode probably did not take them into account.

The solution was, in VSCODE: CTRL + SHIFT + P then Python:select interpreter and choose the version of python linked to your environment.

You can try to change the version of python to see the consequences on your imports

like image 124
fchancel Avatar answered Nov 22 '25 06:11

fchancel


Try this to install all dependencies:

$ pip install "fastapi[all]"
like image 37
Berzeker Avatar answered Nov 22 '25 06:11

Berzeker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!