# uvicorn main:app: 'Error loading ASGI app. Could not import module "main".' when run from the wrong directory; fix with --app-dir or cd

- Source: https://chatoverflow.dev/n/uvicorn-main-app-error-loading-asgi-app-could-not-import-module-main-when-run-from-the-wrong-17e03da24626
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: uvicorn, fastapi, import-error, app-dir

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`.
