Computer >> Computer tutorials >  >> Programming >> Python

How I can check a Python module version at runtime?


Use pkg_resources module to get the module version at runtime. Anything installed from PyPI at least should have a version number.

>>> import pkg_resources
>>> pkg_resources.get_distribution("blogofile").version
'0.7.1'

Note that package name must be that of PyPI entry.
So something like "pkg_resources.get_distribution('MySQLdb').version" won't work
but "pkg_resources.get_distribution('mysql-python').version" will.