osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Import module from a different subdirectory


Rich Shepard <rshepard at appl-ecosys.com> writes:

>
> $ 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/python37.zip',
> '/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
> text_act_de.py I get the error that model.py is not found in the classes
> subdirectory. I don't see how my directory structure, file locations, and
> paths differ from your examples.

In a previous message the error was that 'classes' wasn't found, not that model.py wasn't found in classes, i.e. it was the same error as Peter got.

So to get this working you must make sure 'classes' is inside a directory that is in sys.path, for example by adding:

sys.path.insert(0, '..')
-- 
Piet van Oostrum <piet-l at vanoostrum.org>
WWW: http://piet.vanoostrum.org/
PGP key: [8DAE142BE17999C4]