[Python] Python not recognizing imports

Discussão em 'Python' iniciado por Stack, Fevereiro 24, 2025.

  1. Stack

    Stack Membro Participativo

    I have the following structure in my code:

    src/
    __init__.py
    models/
    __init__.py
    routers/
    __init__.py
    concrete_model/
    __init__.py
    routes.py
    repositories/
    __init__.py
    main.py
    tests/
    __init__.py
    routers/
    concrete_model/
    __init__.py
    requirements.txt
    readme.md


    But I'm having trouble with the imports for some reason. More concretely:

    src/routes/routes.py

    api_router = APIRouter()


    main.py

    from src.routes.routes import api_router


    Is failing with ModuleNotFoundError: No module named 'src'.

    If it's any worth, this is how I have my Python version set up:

    pyenv install 3.13.2
    pyenv exec python -m venv .venv
    source .venv/bin/activate
    pip install -r requirements.txt


    This is a fastapi app, so I'm tying to run

    fastapi dev src/main.py

    Running tests fail similarly. What is going on?

    When trying to run my app

    Continue reading...

Compartilhe esta Página