-1

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.

CutePoison
  • 4,679
  • 5
  • 28
  • 63

1 Answers1

0

Try from from DirA import func_A

Oliver Hnat
  • 797
  • 4
  • 19