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


当前回答

下面是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 /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 freeze > requirements.txt

将在当前位置的活动环境中创建一个包含所有已安装包和已安装版本号的需求文件。运行

pip install -r requirements.txt

将安装需求文件中指定的包。

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