Finding packages visible to your Python code

Found somewhere on the Internet – sorry, dear, unknown source for not quoting you :(

import pkg_resources
installed_packages = pkg_resources.working_set
installed_packages_list = sorted(["%s==%s" % (i.key, i.version)
  for i in installed_packages])
print(installed_packages_list)

There is a high probability I have taken it from here: link