有没有办法找到使用easy_install或pip安装的所有Python PyPI包?我的意思是,不包括发行版工具(在Debian上的apt-get)安装的所有东西。


当前回答

至少对于Ubuntu(也许其他的)来说是这样工作的(灵感来自于这个线程之前的一篇文章):

printf "Installed with pip:";
pip list 2>/dev/null | gawk '{print $1;}' | while read; do pip show "${REPLY}" 2>/dev/null | grep 'Location: /usr/local/lib/python2.7/dist-packages' >/dev/null; if (( $? == 0 )); then printf " ${REPLY}"; fi; done; echo

其他回答

PIP冻结列出所有已安装的包,即使不是通过PIP /easy_install。 在CentOs/Redhat上可以找到通过rpm安装的包。

PIP冻结将输出已安装包及其版本的列表。它还允许您将这些包写入文件,以便稍后用于设置新环境。

https://pip.pypa.io/en/stable/reference/pip_freeze/#pip-freeze

pip. get_installed_distributors()将给出已安装包的列表

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

对于那些没有安装pip的人,我在github上找到了这个快速脚本(适用于Python 2.7.13):

import pkg_resources
distros = pkg_resources.AvailableDistributions()
for key in distros:
  print distros[key]

PIP列表[选项] 你可以在这里看到完整的参考资料