Import module from a different subdirectory
On Sat, 18 May 2019, Peter J. Holzer wrote:
> "" is in sys.path, so "classes" and classes.model are found.
> Now lets go to a different subdirectory:
> This doesn't work, since there is no classes/model.py in "", only in "..".
> But if I add a PYTHONPATH, it works again:
The project layout, briefly, is:
All subdirectories contain a __init__.py file to identify them as packages.
'classes/' contains model.py; 'gui/' contains test_act_de.py.
The project root directory is present in both PYTHONPATH and sys.path:
$ echo $PYTHONPATH
Python 3.7.3 (default, Mar 26 2019, 06:40:28)
[GCC 5.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
['', '/home/rshepard/development/bustrac', '/usr/lib/python37.zip', '/usr/lib/python3.7', '/usr/lib/python3.7/lib-dynload', '/usr/lib/python3.7/site-packages']
When the gui/ subdirectory is the current working directory and I try to run
text_act_de.py I get the error that model.py is not found in the classes
subdirectory. I don't see how my directory structure, file locations, and
paths differ from your examples.