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


当前回答

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

其他回答

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

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

从pip的1.3版本开始,您现在可以使用pip list

它有一些有用的选项,包括显示过期包的能力。下面是文档:https://pip.pypa.io/en/latest/reference/pip_list/

下面是fedora或其他rpm发行版的一行代码(基于@barraponto tips):

find /usr/lib/python2.7/site-packages -maxdepth 2 -name __init__.py | xargs rpm -qf | grep 'not owned by any package'

将此附加到上一个命令以获得更清晰的输出:

 | sed -r 's:.*/(\w+)/__.*:\1:'

下面的代码有点慢,但是它给出了pip所知道的一个格式良好的包列表。也就是说,并不是所有的都是“由”pip安装的,但是它们都应该能够由pip升级。

$ pip search . | egrep -B1 'INSTALLED|LATEST'

它慢的原因是它列出了整个pypi回购的内容。我提交了一张罚单,建议pip list提供类似的功能,但更有效。

示例输出:(将搜索限制为一个子集,而不是'。’。)

$ pip search selenium | egrep -B1 'INSTALLED|LATEST'

selenium                  - Python bindings for Selenium
  INSTALLED: 2.24.0
  LATEST:    2.25.0
--
robotframework-selenium2library - Web testing library for Robot Framework
  INSTALLED: 1.0.1 (latest)
$

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