Skip to content

Instantly share code, notes, and snippets.

@mtayseer
Last active August 29, 2015 14:01
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mtayseer/de7800ceda142155a2ae to your computer and use it in GitHub Desktop.
Save mtayseer/de7800ceda142155a2ae to your computer and use it in GitHub Desktop.
Print a list of all installed Python packages & their dependencies
import pkg_resources, pprint
requires = {p.key: [r.key for r in p.requires()] for p in pkg_resources.working_set}
def graph(pkg):
if not requires[pkg]:
return {pkg: {}}
return {pkg: {k: v for p in requires[pkg] for k, v in graph(p).items() }}
pprint.pprint({k: v for r in requires for k, v in graph(r).items()})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment