Zurab Skhiladze
Zurab Skhiladze

Reputation: 233

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)

Upvotes: 19

Views: 95191

Answers (4)

Sardar
Sardar

Reputation: 648

I had the same problem, I uninstalled fastapi several times and then reinstalled it, but it didn't work. I closed and reopened vscode several times, but it didn't work. But when I closed the terminal inside VScode and created a new terminal again, the problem was solved.

Upvotes: 10

Wahib Mzali
Wahib Mzali

Reputation: 150

Try this :

python -m pip install fastapi uvicorn[standard]

Upvotes: 0

fchancel
fchancel

Reputation: 2699

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

Upvotes: 15

Berzeker
Berzeker

Reputation: 189

Try this to install all dependencies:

$ pip install "fastapi[all]"

Upvotes: 14

Related Questions