有没有办法列出点子的依赖/要求?

没有通过安装,我想快速看到所有的pip install将安装的软件包。

用pip直接得到的最接近的是使用--no-install参数:

 pip install --no-install <package> 

例如,这是安装芹菜时的输出:

 Downloading/unpacking celery Downloading celery-2.5.5.tar.gz (945Kb): 945Kb downloaded Running setup.py egg_info for package celery no previously-included directories found matching 'tests/*.pyc' no previously-included directories found matching 'docs/*.pyc' no previously-included directories found matching 'contrib/*.pyc' no previously-included directories found matching 'celery/*.pyc' no previously-included directories found matching 'examples/*.pyc' no previously-included directories found matching 'bin/*.pyc' no previously-included directories found matching 'docs/.build' no previously-included directories found matching 'docs/graffles' no previously-included directories found matching '.tox/*' Downloading/unpacking anyjson>=0.3.1 (from celery) Downloading anyjson-0.3.3.tar.gz Running setup.py egg_info for package anyjson Downloading/unpacking kombu>=2.1.8,<2.2.0 (from celery) Downloading kombu-2.1.8.tar.gz (273Kb): 273Kb downloaded Running setup.py egg_info for package kombu Downloading/unpacking python-dateutil>=1.5,<2.0 (from celery) Downloading python-dateutil-1.5.tar.gz (233Kb): 233Kb downloaded Running setup.py egg_info for package python-dateutil Downloading/unpacking amqplib>=1.0 (from kombu>=2.1.8,<2.2.0->celery) Downloading amqplib-1.0.2.tgz (58Kb): 58Kb downloaded Running setup.py egg_info for package amqplib Successfully downloaded celery anyjson kombu python-dateutil amqplib 

无可否认的是,这确实给临时文件留下了一些麻烦,但它确实达到了目标。 如果你使用virtualenv(你应该这样做),清理就像删除<virtualenv root>/build目录一样简单。

被接受的答案已经不再适用于更多当前版本的点子,并且没有仔细阅读多个评论就不会立即给出答案,所以我提供了一个更新的答案。

这是用pip版本8.1.29.0.1testing的。

要获得输出,不要在Linux上使用当前目录

 pip download [package] -d /tmp --no-binary :all: 

-d告诉pip下载文件的目录。

更好的方法是使用这个脚本,参数是包的名称,只获取依赖关系作为输出:

 #!/bin/sh PACKAGE=$1 pip download $PACKAGE -d /tmp --no-binary :all: \ | grep Collecting \ | cut -d' ' -f2 \ | grep -v $PACKAGE 

也可在这里 。

当且仅当安装包时,可以使用pip show <package> 。 在输出结尾查找“ Requires: ”。 显然,这打破了你的要求,但可能是有用的。

例如:

 $ pip --version pip 7.1.0 [...] $ pip show pytest --- Metadata-Version: 2.0 Name: pytest Version: 2.7.2 Summary: pytest: simple powerful testing with Python Home-page: http://pytest.org Author: Holger Krekel, Benjamin Peterson, Ronny Pfannschmidt, Floris Bruynooghe and others Author-email: holger at merlinux.eu License: MIT license Location: /home/usr/.tox/develop/lib/python2.7/site-packages Requires: py 

应该使用命令pip install <package> --download <path> ,如@radtek的注释中所述,自7.0.0(2015-05-21)起,–no-install将从pip 删除 。 这将把需要的依赖下载到<path>

另一个select是使用类似于这个的助手脚本,它使用pip.req.parse_requirements API来分析requirements.txt文件,使用distutils.core.setup替代parsingsetup.py文件。

在CASE中你已经安装了软件包,这个脚本可以通过运行@Sardathrion提到的命令pip show从需求文件中获取所有的依赖关系。

 import commands fil = open("requirements.txt") for package_line in fil.readlines(): if "==" in package_line: package = package_line.split("==")[0] elif "[" in package_line: package = package_line.split("[")[0] else: package = package_line output = commands.getoutput('pip show %s' % package) try: required = output.split("\n")[-1].split(":")[1] except Exception as e: required = "" print "error {} in package {}".format(e, package) if len(required) > 1: print package, "-- ****%s***" % required