Module import problem

Gordon McMillan gmcm at hypernet.com
Tue Feb 29 01:30:37 CET 2000


Anthony DeLorenzo wrote:

> I'm having the dumbest problem trying to import a module.  I can't figure
> it out at all.  Basically, I'm on a win32 system.  The directory 
> \py152\lib is on my python path, and I'm trying to import the module
> \py152\lib\gadfly\gadfly.py.
> 
> So, I use this:
> import gadfly.gadfly

This only works if gadfly is a package. A package is a 
directory on sys.path that has an __init__.py (which may be 
empty) in it. You could try adding an (empty) __init__.py. It 
will probably work.

Generally, if you're installing something that is not 
packagized, you should use a .pth file. E.g., if you unzipped 
gadfly to d:/chordate/gadfly, then you should create a file
\py152\gadfly.pth
with one line:
d:/chordate/gadfly

 
> And for some incomprehensible reason it doens't work.  I've used this 
> statement to import other modules in sub-folders, but it just won't
> work for this particular one.  Any ideas, because I'm stumped.  The 
> only way I can get it to import is by running python from the gadfly
> directory, so I do at least know that the module exists.
> 
> Tony
> 
> 
> -- 
> # Anthony DeLorenzo <drgonzo at canada.com>
> # http://www.vex.net/~gonzo/
> # mojo wire: 209-391-8932
> -- 
> http://www.python.org/mailman/listinfo/python-list



- Gordon




More information about the Python-list mailing list