I have a directory structure like:
mycode
|
└-----dirA
| └─---- fileA.py
└─----dirB
└─---- fileB.py
How do I import fileB.object from fileA.py? I have __init__.py's in all the folders, including "mycode", but I continually get errors that I can't find fileB.py from fileA.py, and relative imports don't work either.
import sys print(sys.path)to top of the file you are running.. This will give some idea about what are the folders currently in system pathfilaA.pyis executed. Are you in thedirAdirectory and running as a script (e.g.python3 fileA.py)? Does some other scriptimport mycode.dirA.fileA? In either case, the parent ofmycodeneeds to be insys.path. The usual way to do that is to make the package installable, and then install it. There are tricks (hacks) to get around that, but installing is the normal solution.