I am having the same question as Import from sibling directory but, the idea of having __init__
files does not solve it.
So far I have the following structure:
main/
│ └── __init__.py
├── DirA/
│ ├── __init__.py
│ ├── func_A.py
├── DirB/
│ ├── __init__.py
│ ├── func_B.py
(all __init__
are empty)
I just want to use func_A
in func_B
- see below for the different errors when the lines are written in func_B
:
from ..DirA import func_A #ImportError: attempted relative import with no known parent package
from main.DirA import func_A #ModuleNotFoundError: No module named 'main'
from .DirA import func_A #ImportError: attempted relative import with no known parent package
from DirA import func_A #ModuleNotFoundError: No module named 'func_A'
I have tried running func_B
within dirB
and in main
but it does not work.