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?
pkg_resources is a module used to find and manage Python package/version dependencies and access bundled files and resources, including those inside of zipped . egg files.
The pkg_resources module distributed with setuptools provides an API for Python libraries to access their resource files, and for extensible applications and frameworks to automatically discover plugins.
>>> import pkg_resources >>> pkg_resources.get_distribution("PIL").version '1.1.7'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With