Skip to content

Instantly share code, notes, and snippets.

@bc-lee
Created May 9, 2021 04:58
Show Gist options
  • Save bc-lee/3b047700a3c4f111a34acbdfa4e9e25a to your computer and use it in GitHub Desktop.
Save bc-lee/3b047700a3c4f111a34acbdfa4e9e25a to your computer and use it in GitHub Desktop.
print_python_package.py
#!/usr/bin/env python3
# inspired from https://stackoverflow.com/a/53805392
import pkg_resources
try:
from pip import get_installed_distributions
except:
from pip._internal.utils.misc import get_installed_distributions
for _, package in sorted([('%s %s' % (i.location, i.key), i) for i in get_installed_distributions()]):
print(f"{package.key}=={package.version} # {package.location}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment