Importing module from another subdirectory

Rich Shepard rshepard at appl-ecosys.com
Wed Apr 17 16:50:25 EDT 2019


What is the proper syntax to import the model class in the model/
subdirectory into a tkinter view module, e.g., activities.py? The syntax,
'import model as m' fails because it is not in the same subdirectory as the
importing module.

The program directory tree is:

bustrac/
    README.rst
    bustrac.py*
    controller/
    model/
    scripts/
    views/

Running pdb in python3-3.7.3 produces the same error:
$ 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 pdb
>>> import activities_data_entry
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File "/home/rshepard/development/business_tracker/views/activities_data_entry.py", line 1, in <module>
     import model.activities as act
ModuleNotFoundError: No module named 'model'

My previous use of python has had all files in the same directory so I've
not before had to learn how to address this issue. Pointers appreciated.

Regards,

Rich



More information about the Python-list mailing list