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!

2 Answers 2

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.

0
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
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.