Import module from a different subdirectory

Rich Shepard rshepard at appl-ecosys.com
Fri May 17 11:30:25 EDT 2019


On Thu, 16 May 2019, Rich Shepard wrote:

> The project directory contains subdirectories, including gui/ (with the
> tkinter views) and classes/ with the SQLAlchemy model.py.

Getting closer, but still missing a piece of the solution.

First, I added __init__.py to each module subdirectory to specify that the
subdirectory is a package.

Second, in ~/.bash_profile I added two lines, the first is the project's
root directory:

PYTHONPATH=$HOME/development/bustrac
export PYTHONPATH

Testing this suggests that python is finding the 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 os
>>> os.environ["PYTHONPATH"]
'/home/rshepard/development/bustrac'

but the import is still not working.

Do I need to specify each bustrac/ subdirectory in the PYTHONPATH? If not,
what am I still missing?

Regards,

Rich


More information about the Python-list mailing list