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

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.

Updated on 01-Oct-2019 07:11:07