Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which package is Python using?

Tags:

python

package

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!

like image 283
dotancohen Avatar asked Jul 10 '13 05:07

dotancohen


2 Answers

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.

like image 96
Lennart Regebro Avatar answered Sep 22 '22 11:09

Lennart Regebro


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
like image 44
geertjanvdk Avatar answered Sep 21 '22 11:09

geertjanvdk