There is no 100% deterministic way for a module to report its version. What there are are conventions and suggestions.
The PEP 8 suggests here that you use a variable of module called __version__
to store the version, however, this is just a suggestion - it is not mandatory for modules to have this variable.
Some modules follow this suggestion and make the version available in __version__
, but others use alternative variables like VERSION
or VER
or simply version
. There are also modules that use a get_version()
function capable of generating the dynamically tag-based number of the version control system used.
Fortunately, both MySQLdb
and zipfile36
you want use the method suggested by PEP 8. Then you can use:
import zipfile36
print(zipfile36.__version__)
import MySQLdb
print(MySQLdb.__version__)