6

I see that one could have several versions of a Python package installed:

$ locate signals.py | grep python
/usr/lib/pymodules/python2.7/zim/signals.py
/usr/lib/pymodules/python2.7/zim/signals.pyc
/usr/lib/python2.7/dist-packages/bzrlib/smart/signals.py
/usr/lib/python2.7/dist-packages/bzrlib/smart/signals.pyc
/usr/lib/python2.7/unittest/signals.py
/usr/lib/python2.7/unittest/signals.pyc
/usr/lib/python3.2/unittest/signals.py

How might I check which version of a package (i.e. which file, not which version number) an application is using? Ignoring the obvious "Zim will use the package at /usr/lib/pymodules/python2.7/zim/signals.py" is there way to see which file is being used for a particular Python package?

Some packages I can crash and look at the backtrace. I don't think that this is the best method, however!

dotancohen
  • 30,064
  • 36
  • 138
  • 197

2 Answers2

8

The __file__ attribute will tell you:

>>> from unittest import signals
>>> signals.__file__
'/usr/lib/python2.7/unittest/signals.pyc'

.pyc are compiled files, so the file you actually are looking for in this case it the /usr/lib/python2.7/unittest/signals.py file.

Lennart Regebro
  • 167,292
  • 41
  • 224
  • 251
3

I hope I understood correctly, but here's how you find out the location of the module you loaded:

shell> python -c 'import jinja2; print jinja2.__file__'
/Library/Python/2.7/site-packages/jinja2/__init__.pyc
geertjanvdk
  • 3,440
  • 24
  • 26