Reputation: 233
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
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
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
Reputation: 189
Try this to install all dependencies:
$ pip install "fastapi[all]"
Upvotes: 14