How to check version of python modules?

PythonServer Side ProgrammingProgramming

When you install Python, you also get the Python package manager, pip. You can use pip to get the versions of python modules. If you want to list all installed Python modules with their version numbers, use the following command:

$ pip freeze

You will get the output:

asn1crypto==0.22.0
astroid==1.5.2
attrs==16.3.0
Automat==0.5.0
backports.functools-lru-cache==1.3
cffi==1.10.0
...

To individually find the version number you can grep on this output on *NIX machines. For example:

$ pip freeze | grep PyMySQL
PyMySQL==0.7.11

On windows, you can use findstr instead of grep. For example:

PS C:\> pip freeze | findstr PyMySql
PyMySQL==0.7.11

If you want to know the version of a module within a Python script, you can use the __version__ attribute of the module to get it. Note that not all modules come with a __version__ attribute. For example,

>>> import pylint
>>> pylint.__version__
'1.7.1'
raja
Published on 19-Dec-2017 18:05:54
Advertisements