Skip to content

Instantly share code, notes, and snippets.

@satishgunjal
Created October 17, 2020 07:25
Show Gist options
  • Save satishgunjal/4f02d793d1f7576e995af30b31e9ebc2 to your computer and use it in GitHub Desktop.
Save satishgunjal/4f02d793d1f7576e995af30b31e9ebc2 to your computer and use it in GitHub Desktop.
Versions of Imported Libraries
import pkg_resources
import types
def get_imports():
for name, val in globals().items():
if isinstance(val, types.ModuleType):
name = val.__name__.split(".")[0]
elif isinstance(val, type):
name = val.__module__.split(".")[0]
if name == "PIL":
name = "Pillow"
elif name == "sklearn":
name = "scikit-learn"
yield name
def get_versions():
imports = list(set(get_imports()))
requirements = []
for m in pkg_resources.working_set:
if m.project_name in imports and m.project_name!="pip":
requirements.append((m.project_name, m.version))
for r in requirements:
print("{}== {}".format(*r))
get_versions()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment