How can I get a list of locally installed Python modules?

前端 未结 30 2157
庸人自扰
庸人自扰 2020-11-22 04:32

I would like to get a list of Python modules, which are in my Python installation (UNIX server).

How can you get a list of Python modules installed in your computer?

30条回答
  •  旧巷少年郎
    2020-11-22 04:52

    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_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)
    

    Please let me know if it will or won't work in previous versions of pip, too.

提交回复
热议问题