I am using Python 3.4
I have a directory structure that looks this:
A
B
c.py
d.py
__init__.py
C
e.py
f.py
__init__.py
g.py
__init__.py
From g.py I can import things from both B and C modules.
I need, in e.py, to import something from c.py
I tried:
import B
and
from B.c import stuff_I_need
For both I get the error:
"No module named B".
I also tried something like:
from A.B.c import stuff_I_need
I am further confused by the fact with an identical directory structure, I can make the imports I need with Python 2.7.
Can you help me figure out what's going on?
Solution:
PACKAGE_PARENT = '..'
SCRIPT_DIR = os.path.dirname(os.path.realpath(os.path.join(os.getcwd(), os.path.expanduser(__file__))))
sys.path.append(os.path.normpath(os.path.join(SCRIPT_DIR, PACKAGE_PARENT)))
Taken from here.