How I can check a Python module version at runtime?

PythonServer Side ProgrammingProgramming

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.

raja
Published on 20-Dec-2017 10:58:48
Advertisements