1

I have the following package structure:

.
├── README.md
├── common
│   ├── __init__.py
│   ├── analysis
│   │   ├── __init__.py
│   │   └── base_analysis.py
│   ├── logger
│       ├── __init__.py
│       └── logger.py
└── scripts
    └── test_analysis
        └── run.py

I would like to access logger in base_analysis.py. If I do this:

from ..logger import Logger

I am getting this error:

ValueError: attempted relative import beyond top-level package

How to import a sub-package from the parent package?

Note: I am running the script from scripts/test_analysis using:

python run.py
ssk
  • 9,045
  • 26
  • 96
  • 169

1 Answers1

1

following changes to the calling python run.py script fixed it;

from logger.logger import Logger
ssk
  • 9,045
  • 26
  • 96
  • 169