TobaSko
TobaSko

Reputation: 373

FastAPI cannot find main.py: `ERROR: Error loading ASGI app. Could not import module "main"

I know usually it is something about project structure that raises this error.

But my project structure is the simplest one:

.
├── blog.db
├── database.py
├── main.py
├── models.py
├── poetry.lock
├── __pycache__
│   ├── database.cpython-39.pyc
│   ├── main.cpython-39.pyc
│   ├── models.cpython-39.pyc
│   ├── schemas.cpython-39.pyc
│   └── services.cpython-39.pyc
├── pyproject.toml
├── requirements.txt
├── schemas.py
└── services.py
 

Yet every time I run

uvicorn main:app --reload

I get

ERROR: Error loading ASGI app. Could not import module "main".

So what exactly am I doing wrong if I have all my files in the same folder?

Upvotes: 0

Views: 4954

Answers (1)

Quang Tu
Quang Tu

Reputation: 31

I have the same problem with running fastAPI. After checking the file path and everything, I figure the solution is very simple. You just need to save your python file (in this case "main.py") before run uvicorn command on cmd. That's it.

Upvotes: 3

Related Questions