0

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?

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
TobaSko
  • 323
  • 1
  • 3
  • 9
  • From *where* are you running your `uvicorn` command? Is it within this same directory? – Gino Mempin Jul 30 '21 at 09:55
  • Does this answer your question? [FastAPI throws an error (Error loading ASGI app. Could not import module "api")](https://stackoverflow.com/questions/60819376/fastapi-throws-an-error-error-loading-asgi-app-could-not-import-module-api) – Gino Mempin Jul 30 '21 at 09:58
  • @GinoMempin I do "cd" command to the same directory yes – TobaSko Jul 30 '21 at 10:49
  • Can you [edit] to add more details to reproduce your issue? Specifically, copy-paste the output of your terminal showing: 1) `cd` or `pwd` that you indeed are in that directory, 2) `ls` that the current directory does have main.py, and 3) the complete call and output of the `uvicorn main:app` command. – Gino Mempin Jul 31 '21 at 00:56

1 Answers1

2

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.

Quang Tu
  • 21
  • 2