module import search path strangeness
toby.o.h.white at googlemail.com
Tue Aug 12 10:24:10 CEST 2008
On Aug 12, 4:59 am, "Gabriel Genellina" <gagsl-... at yahoo.com.ar>
> En Mon, 11 Aug 2008 19:19:19 -0300, tow <toby.o.h.wh... at googlemail.com>
> escribi :
> > I have a python script (part of a django application, if it makes any
> > difference) which is exhibiting the following behaviour:
> > import my_module # succeeds
> > imp.find_module("my_module") # fails, raising ImportError
> > which is completely baffling me. According to sys.path, both should
> > fail; the directory containing my_module is not in sys.path (though
> > the my_module directory itself is).
> my_module is not a module but a package, right? Else I don't understand
> the above statement.
Sorry, sloppy terminology on my part, yes, my_module is a package.
> > More puzzlingly, printing out
> > my_module.__file__ gives:
> > /home/tow/test/my_module/../my_module/__init__.pyc
> > I don't really understand what the ".." is doing in there.
> > Can someone explain what I'm missing here, it's got me stumped.
> Perhaps you have ".." in sys.path? And the current directory happens to be
The current directory is actually a subdirectory of /home/tow/test/
but ".." is not in sys.path (nor is anything containing "..") In any
it were a matter of sys.path, surely the imp.find_module call above
Basically, I had thought that import and imp.find_module used exactly
search path, but the above example shows that at least in this
don't; import is picking up additional search paths from somewhere -
what am I missing?
More information about the Python-list