Created
October 17, 2020 07:25
-
-
Save satishgunjal/4f02d793d1f7576e995af30b31e9ebc2 to your computer and use it in GitHub Desktop.
Versions of Imported Libraries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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