Find the location of a loaded module

Aaron Scott aaron.hildebrandt at
Fri Feb 20 21:23:03 CET 2009

Here's another clue: if I'm trying to run the script from the
directory 'act1', but it's loading the module from 'act2', if I rename
the module directory in 'act2' and refresh, the module still reports
that it's running from '/home/www/---/docs/act2/story/game.pyc'...
even though that files no longer exists. If I refresh a few more
times, both 'act1' and 'act2' will load the module from 'act1's
directory (even though the directory doesn't appear in sys.path when
you try to load it from 'act2').

So, Python is trying to import a module from a directory that isn't in
sys.path, and will generally default to running the module from the
directory where it was last run. If I run it from 'act1', then 'act2',
both times it will load the module from 'act1'. If I do it the other
way around, it will load the module from 'act2' both times.

The question now is... why is it loading from a directory that isn't
in sys.path? How can I avoid this?

More information about the Python-list mailing list