-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Description
I am encountering two main issues related to import management:
- Circular Import: I want to import from a sibling package. If I do
from pneuma.utils.response import Response, ResponseStatusfrom registration.py and try to run the script directly, ModuleNotFoundError: No module named 'pneuma' occurs. Additionally, if pneuma.py is run, ImportError: cannot import name 'Registration' from partially initialized module 'registration.registration' (most likely due to a circular import) (xxx\Pneuma\pneuma\registration\registration.py) occurs. - Relative import error: If I do
from ..utils.response import Response, ResponseStatusinstead, ImportError: attempted relative import with no known parent package occurs, both when running the scripts directly and running pneuma.py
Below is the current simplified project structure:
pneuma/
├── __init__.py
├── registration/
│ ├── __init__.py
│ ├── registration.py
│ └── helper.py
├── utils/
│ ├── __init__.py
│ ├── response.py
└── pneuma.py
Right now, the fix is doing sys.path.append(str(Path(__file__).resolve().parent.parent)) and importing with from utils.response import Response, ResponseStatus to import from sibling packages.
Request for help:
- Suggestions for restructuring the code to avoid circular imports.
- Best practices for import management in this project.
Metadata
Metadata
Assignees
Labels
No labels