xxxxxxxxxx
import pkg_resources
def get_package_version(package_name):
try:
version = pkg_resources.get_distribution(package_name).version
return version
except pkg_resources.DistributionNotFound:
return "Package not found."
# Example usage:
package_name = 'requests'
version = get_package_version(package_name)
print(f"The version of {package_name} is {version}.")
xxxxxxxxxx
# type below command based on which module version you want to know.
$ python -m django --version
$ python -m pandas --version
xxxxxxxxxx
Linux:
$ pip freeze | grep lxml
lxml==2.3
Windows:
c:\> pip freeze | findstr lxml
lxml==2.3
Python:
$ python -c "import requests; print(requests.__version__)"
2.14.2
xxxxxxxxxx
#Let's say you want to check tensorflow version
import tensorflow as tf
tf.__version__
xxxxxxxxxx
pip show seaborn #or whichever name
# or use
import seaborn as sns
sns.__version__
xxxxxxxxxx
$ pip show pandas
Name: pandas
Version: 0.22.0
Summary: Powerful data structures for data analysis, time series,and statistics
Home-page: http://pandas.pydata.org
Author: The PyData Development Team
Author-email: pydata@googlegroups.com
License: BSD
Location: /usr/local/lib/python3.6/site-packages
Requires: pytz, numpy, python-dateutil