Alex Popescu nospam.themindstorm at
Sat Jul 28 01:21:40 CEST 2007

"Kevin T. Ryan" <kevin.t.ryan at> wrote in 
news:1185576929.136179.174440 at

> Hi All -
> I'm having a problem and I hope you can help.  I can't seem to import
> packages from within the package substructure as I think I should be
> able to.  For example, I create a directory structure as follows:
> testpkg
> [empty]
>   testsub1/
> [empty]
> [import testpkg.testsub2.good; print "hello from bad"] <-
> error
>   testsub2/
> [empty]
> [print "hello from good"]
> Whenever I try to run (just python from within the
> testsub2 subdirectory or from above the testpkg directory) I get an
> error.  For example:
> $ python testpkg/testsub1/
> Traceback (most recent call last):
>   File "testpkg/testsub1/", line 1, in <modul
>     import testpkg.testsub2.good
> ImportError: No module named testpkg.testsub2.good
> How can I get my subpackages to recognize other subpackages in the
> same top-level package?  Thanks in advance!!
> Kevin

When executing python will be looking for imported module (in the 
standard path) and then in your current directory (so to find it you 
should have testsub1/testpkg/testsub2). You can solve this by adding 
your toplevel director (the parent of testpkg) to the PYTHONPATH. 

.w( the_mindstorm )p.

More information about the Python-list mailing list