如何使用 PIP 查看依赖于某个包的所有包?
问题描述
我想查看依赖于带有 PIP 的某个包的包列表.也就是说,给定django
,我想看看django-cms
、django-filer
,因为我已经安装了这些包并且它们都有django
作为依赖.
I would like to see a list of packages that depend on a certain package with PIP. That is, given django
, I would like to see django-cms
, django-filer
, because I have these packages installed and they all have django
as dependency.
解决方案
更新(2021):
从 pip
版本 10 开始,您可以:
Since pip
version 10 you can do:
pkg=httplib2
pip show $pkg | grep ^Required-by
或用于 bash
pkg=httplib2
grep ^Required-by <(pip show $pkg)
所以你可以创建一个别名,如:
so you could create an alias like:
alias pyreq='pip show $pkg | grep ^Required-by'
并通过以下方式查询:
pkg=httplib2 pyreq
应该给出(对于 ubuntu):
which should give (for ubuntu):
Required-by: lazr.restfulclient, launchpadlib
原文:
Original:
很简单:
pip show <insert_package_name_here>| grep ^Requires
或者反过来:(对不起,我弄错了!)
Or the other way around: (sorry i got it wrong!)
for NAME in $(pip freeze | cut -d= -f1); do REQ=$(pip show $NAME| grep Requires); if [[ "$REQ" =~ "$REQUIRES" ]]; then echo $REQ;echo "Package: $NAME"; echo "---" ; fi; done
在此之前将您的搜索字符串设置为:
before that set your search-string with:
REQUIRES=django
基本上你必须遍历整个列表并查询每一个.这可能需要一些时间.
essentially you have to go through the whole list and query for every single one. That may take some time.
它也只适用于已安装的包,我没有看到 pip 提供对未安装包的依赖.
相关文章