Adapted from gafortiby's answer: a shorter version to list only explicit list of packages. I found this suitable to memorize versions of the most important packages used in a jupyter notebook (for other readers or future use):
import pkg_resources
# list packages to be checked
root_packages = [
'geoviews', 'geopandas', 'pandas', 'numpy',
'matplotlib', 'shapely', 'cartopy', 'holoviews',
'mapclassify', 'fiona', 'bokeh']
# print versions, but check if package is imported first
for m in pkg_resources.working_set:
if m.project_name.lower() in root_packages:
print(f"{m.project_name}=={m.version}")
Output:
Shapely==1.7.0
pandas==1.0.1
numpy==1.18.1
matplotlib==3.1.3
mapclassify==2.2.0
holoviews==1.12.7
geoviews==1.6.6
geopandas==0.6.3
Fiona==1.8.13
Cartopy==0.17.0
bokeh==1.4.0
Enhanced version with nicer display:
import pkg_resources
from IPython.display import display
import pandas as pd
root_packages = [
'geoviews', 'geopandas', 'pandas', 'numpy', 'cloudpickle',
'matplotlib', 'shapely', 'cartopy', 'holoviews',
'mapclassify', 'fiona', 'bokeh', 'pyproj', 'ipython',
'jupyterlab']
root_packages.sort(reverse=True)
root_packages_list = []
for m in pkg_resources.working_set:
if m.project_name.lower() in root_packages:
root_packages_list.append([m.project_name, m.version])
display(pd.DataFrame(
root_packages_list,
columns=["package", "version"]
).set_index("package").transpose())
Output:
