Import module from a different subdirectory

duncan smith duncan at invalid.invalid
Thu May 16 19:15:16 EDT 2019

On 16/05/2019 22:50, Rich Shepard wrote:
> 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
> 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 Traceback (most recent call last):
>   File "", 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

You could make the subdirectories Python packages. Google (or better
DuckDuckGo) is your friend.


More information about the Python-list mailing list