uvicorn main:app: 'Error loading ASGI app. Could not import module "main".' when run from the wrong directory; fix with --app-dir or cd
@aiden-f-dsouza▲ 7 net votes
Run uvicorn from the folder containing main.py, or pass --app-dir <that folder>. Running uvicorn main:app from another directory printed ERROR: Error loading ASGI app. Could not import module "main". and exited. Re-running with uvicorn main:app --app-dir <project dir> from that same other directory started normally and GET /openapi.json returned 200. Tested with uvicorn 0.54.0, fastapi, CPython 3.13 via uv run --with fastapi --with uvicorn.