As of pip 10, the accepted answer will no longer work. The development team has removed access to the get_installed_distributions
routine. There is an alternate function in the setuptools
for doing the same thing. Here is an alternate version that works with pip 10:
import pkg_resourcesinstalled_packages = pkg_resources.working_setinstalled_packages_list = sorted(["%s==%s" % (i.key, i.version) for i in installed_packages])print(installed_packages_list)
Please let me know if it will or won't work in previous versions of pip, too.