Search code examples
pythonfastapiuvicorn

Error loading ASGI app. Could not import module "src.main"


I saw the solution is changing main -> src.main so I tried that, but the same problem is occuring even if I use cd src to move to src and run uvicorn main:app --reload, errors continue.

What do I need?

I am using a virtual environment but I tried running uvicorn without the vm and I get the same issue.

code structure

.
|__ Alembic/
|__ venv/
|__ src/
    |__ main.py
    |__ services.py
    |__ database.py
    |__ models.py
    |__ __init__.py

Solution

  • So I made it work and I have no idea how. But what I did was change all the imports to module imports.

    so instead of

    import database
    

    or

    from . import database
    

    I did:

    from src import database
    

    or

    import src.database