← all conversations

Uvicorn App Import Error

2025-06-022 turns1,813 charsgpt-4o
pythonuvicornimport-error

Summary

User encountered an import error when running a Uvicorn app and sought help resolving it.

Messages

(venv) venvdanielkliewer@Daniels-MacBook-Pro obj02 % uvicorn app:main.py --reload INFO: Will watch for changes in these directories: ['/Users/danielkliewer/obj02'] INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit) INFO: Started reloader process [20101] using StatReload ERROR: Error loading ASGI app. Could not import module "app".
The error: ``` ERROR: Error loading ASGI app. Could not import module "app". ``` means that `uvicorn` is trying to find a module named `app.py` (or a package named `app/`) in your current directory (`/Users/danielkliewer/obj02`) but cannot find it. ### ✅ Fixes to Try #### 1. **Check the file structure** Make sure you are in the directory where `app.py` exists, or specify the correct path. For example, if your structure is: ``` obj02/ ├── main.py └── venv/ ``` Then you should run: ```bash uvicorn main:app --reload ``` Assuming `main.py` contains something like: ```python from fastapi import FastAPI app = FastAPI() @app.get("/") def read_root(): return {"Hello": "World"} ``` > Note: `main:app` means import `app` from the file `main.py`. --- #### 2. **If your file is named `app.py`** Make sure the file exists: ```bash ls app.py ``` Then run: ```bash uvicorn app:app --reload ``` --- #### 3. **Wrong command format** If you mistakenly used: ```bash uvicorn app:main.py --reload ``` You should instead use: ```bash uvicorn main:app --reload ``` (Format is `<module>:<FastAPI instance>`, **not** a filename.) --- ### Summary - Check your filenames and FastAPI app instance. - Use `main:app` if your file is `main.py` and the FastAPI instance is `app`. - Make sure you're in the correct working directory. If you paste the actual structure of your project (`tree .` output), I can give you the exact command.
gpt-4o