Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get a python module's version number through code? [duplicate]

Tags:

python

I'm trying to get the version number of a specific few modules that I use. Something that I can store in a variable.

like image 945
Joe Schmoe Avatar asked Aug 19 '10 16:08

Joe Schmoe


People also ask

What is __ version __ in Python?

It provides a __version__ attribute. It provides the standard metadata version. Therefore it will be detected by pkg_resources or other tools that parse the package metadata (EGG-INFO and/or PKG-INFO, PEP 0345).


1 Answers

Use pkg_resources(part of setuptools). Anything installed from PyPI at least has a version number. No extra package/module is needed.

>>> import pkg_resources >>> pkg_resources.get_distribution("simplegist").version '0.3.2' 
like image 119
softvar Avatar answered Sep 20 '22 16:09

softvar