Reputation:
the file name is main.py anytime i run uvicorn main:app --reload
i get the error under the code.
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
async def root():
return {"message": "Hello World"}
Error
INFO: Will watch for changes in these directories: ['/Users/Documents/main.py']
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO: Started reloader process [58745] using statreload
ERROR: Error loading ASGI app. Could not import module "main".
Upvotes: 2
Views: 7518
Reputation: 31
check that the name of your file should be main or if that's name is 'example' you shuld write: uvicorn example:app --reload
Upvotes: -1
Reputation: 263
Are you running the command uvicorn main:app --reload in the same directory as the file main.py is? Probably that's your problem. I tested your code and it is working for me.
Upvotes: 4