There is no 100% deterministic way for a module to inform its version. There are conventions and suggestions.
THE PEP 8 suggests here that a module variable called __version__
to store the version, however, this is only a suggestion - it is not required that modules have this variable.
Some modules follow this suggestion and make the version available in __version__
, but others use alternative variables such as VERSION
or VER
or simply version
. There are also modules that use a function get_version()
capable of generating the number dynamically based on tags of the version control system used.
Luckily, both the MySQLdb
as to the zipfile36
you want to use the method suggested by PEP 8. Then you can use:
import zipfile36
print(zipfile36.__version__)
import MySQLdb
print(MySQLdb.__version__)
Usually packages have in
__init__.py
a variable with the version. You can access the source code of each package and check which variable to evaluate.– Woss