Import module from a different subdirectory

Rich Shepard rshepard at
Sat May 18 12:43:34 EDT 2019

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/ in "", only in "..".
> But if I add a PYTHONPATH, it works again:


The project layout, briefly, is:


All subdirectories contain a file to identify them as packages.
'classes/' contains; 'gui/' contains

The project root directory is present in both PYTHONPATH and sys.path:


$ python3
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
>>> sys.path
['', '/home/rshepard/development/bustrac', '/usr/lib/', '/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 I get the error that is not found in the classes
subdirectory. I don't see how my directory structure, file locations, and
paths differ from your examples.



More information about the Python-list mailing list