tarabyte tarabyte - 4 months ago 17
Python Question

How to check version of python modules?

I just installed the python modules:

construct
and
statlib
with
setuptools
like this:

# Install setuptools to be able to download the following
sudo apt-get install python-setuptools

# Install statlib for lightweight statistical tools
sudo easy_install statlib

# Install construct for packing/unpacking binary data
sudo easy_install construct


I want to be able to (programmatically) check their versions. Is there an equivalent to
python --version
I can run from the command line?

My python version is
2.7.3
.

Answer

I suggest using pip in place of easy_install. With pip, you can list all installed packages and their versions with

pip freeze

For an individual module, you can try __version__ attribute, however there are modules without it:

$ pip freeze | grep lxml
lxml==2.3
$ python -c "import lxml; print lxml.__version__"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
AttributeError: 'module' object has no attribute '__version__'

Last, as you run your command with sudo prefix, I guess you're installing to global python environment. Strongly advise to take look into python virtual environment managers, for example virtualenvwrapper

Comments