As T-Heron notes, it's hard to tell exactly what you're trying to do here, but if I had to hazard a guess I'd say you're running dir1f.py as a script (ala python dir1/dir1f.py
or python dir1f.py
from the dir1
directory) which means you shouldn't use relative imports. Try:
from dir2.dir2f import dir2c
Update: If executing with python dir1f.py
, there are a few ways to go:
- try
python dir1/dir1f.py
from the top-level directory first; or
- move dir2 into dir1 and run
python dir1f.py
from dir1; or
- read up on PYTHONPATH (environment variable)
Also: have a read of PEP8, especially the imports section:
"Absolute imports are recommended, as they are usually more readable
and tend to be better behaved (or at least give better error messages)
if the import system is incorrectly configured (such as when a
directory inside a package ends up on sys.path)."
-- http://pep8.org/#imports
Possibly related, with quite a bit more detail: Relative imports in Python 3