Import module from a different subdirectory

Rich Shepard rshepard at appl-ecosys.com
Thu May 16 17:50:50 EDT 2019


I'm developing a Python3 application using Python3-3.7.3 and
virtualenv-16.5.0 on a Slackware-14.2 host.

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

Within the gui/ directory as the cwd testing the code for a view needs to
import the 'model' module from the class/ subdirectory and I have not been
able to use the correct syntax to import that module. The view module starts
with:

from classes import model as m
import data_entry_validators
from commonDlgs import LabelInput

import tkinter as tk
from tkinter import ttk
from datetime import datetime

When I try to display this UI view I get an error:

$ python3 test_act_de.py 
Traceback (most recent call last):
   File "test_act_de.py", line 1, in <module>
     from classes import model as m
ModuleNotFoundError: No module named 'classes'

Of course, 'classes' is a subdirectory not a module. My web searches have
not found the proper syntax to import the 'model' module from the separate
subdirectory classes and I need to learn how to do this.

Regards,

Rich


More information about the Python-list mailing list