[Python] Python imports from inside the package

Discussão em 'Python' iniciado por Stack, Janeiro 25, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to use a github repository that I cloned locally.

    The repo is structured like this:

    project-name
    | __init__.py
    |____project-name
    | __init__.py
    | http_service.py
    | data.py


    Now I'm trying to import stuff from http_service.py, like this:

    import sys
    sys.path.append('/.../project-name/project-name/')
    from http_service import classname


    But when I do this, an import inside the http_service.py file fails. The error message is: ModuleNotFoundError: No module named 'project-name.data'

    The http_service.py file has this:

    from project-name.data import xyz

    Clearly, I don't understand how this is supposed to work. How can the http_service file import from project-name when it's inside that directory? And what am I supposed to do differently to use this code?

    Continue reading...

Compartilhe esta Página