dotancohen
dotancohen

Reputation: 31481

Which package is Python using?

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!

Upvotes: 6

Views: 116

Answers (2)

geertjanvdk
geertjanvdk

Reputation: 3520

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

Upvotes: 3

Lennart Regebro
Lennart Regebro

Reputation: 172239

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.

Upvotes: 8

Related Questions