the correct answer is to use sys.modules
... it works on everything, even sys
. sys.modules
is a dictionary where the keys are the imported names (modules or packages), and the values are their respective locations. here is some usage output from my Mac:
$ python
Python 2.5.1 (r251:54863, Feb 9 2009, 18:49:36)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys, os, django, google
>>> sys.modules['sys']
<module 'sys' (built-in)>
>>> sys.modules['os']
<module 'os' from '/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/os.pyc'>
>>> sys.modules['django']
<module 'django' from '/Library/Python/2.5/site-packages/Django-1.1.1-py2.5.egg/django/__init__.pyc'>
>>> sys.modules['google']
<module 'google' from '/usr/local/google_appengine/google/__init__.py'>