Find all packages installed with easy_install/pip?

前端 未结 18 1255
醉话见心
醉话见心 2020-11-27 08:47

Is there a way to find all Python PyPI packages that were installed with easy_install or pip? I mean, excluding everything that was/is installed with the distributions tool

18条回答
  •  暖寄归人
    2020-11-27 09:45

    pip.get_installed_distributions() will give a list of installed packages

    import pip
    from os.path import join
    
    for package in pip.get_installed_distributions():
        print(package.location) # you can exclude packages that's in /usr/XXX
        print(join(package.location, package._get_metadata("top_level.txt"))) # root directory of this package
    

提交回复
热议问题