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
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
xxxxxxxxxx
import pkg_resources
def get_package_version(package_name):
try:
# Get the distribution
dist = pkg_resources.get_distribution(package_name)
return dist.version
except pkg_resources.DistributionNotFound:
return None
# Example usage
package_name = 'requests'
version = get_package_version(package_name)
if version:
print(f"The version of {package_name} is: {version}")
else:
print(f"The package {package_name} is not installed.")