I'm trying to get the version number of a specific few modules that I use. Something that I can store in a variable.
38
votes
6 Answers
33
votes
81
votes
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'
15
votes
Starting Python 3.8
, importlib.metadata
can be used as a replacement for pkg_resources
to extract the version of third-party packages installed via tools such as pip
:
from importlib.metadata import version
version('wheel')
# '0.33.4'
7
votes
0
votes
-1
votes
import sys
import matplotlib as plt
import pandas as pd
import sklearn as skl
import seaborn as sns
print(sys.version)
print(plt.__version__)
print(pd.__version__)
print(skl.__version__)
print(sns.__version__)
The above code shows versions of respective modules: Sample O/P:
3.7.1rc1 (v3.7.1rc1:2064bcf6ce, Sep 26 2018, 14:21:39) [MSC v.1914 32 bit (Intel)] 3.1.0 0.24.2 0.21.2 0.9.0 (sys shows version of python )