Getting package version using pkg_resources?

Andreas Jung picture Andreas Jung · Jan 16, 2012 · Viewed 9.1k times · Source

What is the recommended way getting hold of the package version of a package in the $PYTHONPATH or sys.path? I remember that the pkg_resource module has some functionality for this but I can not find any related information. Please don't point me to solution using a version.py file and reading it somehow. Using pkg_resources is the way to go but how exactly?

Answer

AdamKG picture AdamKG · Jan 16, 2012
>>> import pkg_resources
>>> pkg_resources.get_distribution("PIL").version
'1.1.7'