How can I determine from which directory the library is imported in python?

I am trying to change the python library that I downloaded and use. But the changes that I make do nothing. Therefore, I suspect that python is importing another copy of this library from another location on the file system. So that...

When I run import foolibin python, how can I determine where on the file system it gets this library?

+5
source share
3 answers
import foolib
print foolib.__file__

Unfortunately, this only works for some modules. For instance. he is working on a module that I wrote, but not on sys.

+6
source

- sys.modules... , sys. sys.modules - , ( ), - . 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'>
+8

Look at foolib.__file__.

+2
source

All Articles