order of importing modules

Catherine Moroney Catherine.M.Moroney at jpl.nasa.gov
Tue Jan 11 19:30:22 EST 2011


In what order does python import modules on a Linux system?  I have a 
package that is both installed in /usr/lib64/python2.5/site-packages,
and a newer version of the same module in a working directory.

I want to import the version from the working directory, but when I
print module.__file__ in the interpreter after importing the module,
I get the version that's in site-packages.

I've played with the PYTHONPATH environmental variable by setting it
to just the path of the working directory, but when I import the module
I still pick up the version in site-packages.

/usr/lib64 is in my PATH variable, but doesn't appear anywhere else.  I
don't want to remove /usr/lib64 from my PATH because that will break
a lot of stuff.

Can I force python to import from my PYTHONPATH first, before looking
in the system directory?

Catherine



More information about the Python-list mailing list