用 pip 显示反向依赖关系? [英] show reverse dependencies with pip?

查看:25
本文介绍了用 pip 显示反向依赖关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用 pip 显示反向依赖关系?

Is it possible to show the reverse dependencies with pip?

我想知道哪个包需要包foo.以及这个包需要哪个版本的 foo.

I want to know which package needs package foo. And which version of foo is needed by this package.

推荐答案

这对于已经使用 pip 的 python API 安装的包是可能的.有 pip.get_installed_distributions 功能,它可以为您提供当前安装的所有第三方软件包的列表.

This is possible for already installed packages using pip's python API. There is the pip.get_installed_distributions function, which can give you a list of all third party packages currently installed.

# rev_deps.py
import pip
import sys

def find_reverse_deps(package_name):
    return [
        pkg.project_name for pkg in pip.get_installed_distributions()
        if package_name in {req.project_name for req in pkg.requires()}
    ]

if __name__ == '__main__':
    print find_reverse_deps(sys.argv[1])

此脚本将输出需要指定包的包列表:

This script will output the list of packages, that require a specified one:

$python rev_deps.py requests

这篇关于用 pip 显示反向依赖关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆