问题:有没有办法列出点子的依赖关系/要求?
在不进行安装的情况下,我想快速查看pip install
将要安装的所有软件包。
回答 0
接受的答案不再与最新版本的pip有关,并且在不仔细阅读多个注释的情况下也不会立即给出答案,因此我提供了更新的答案。
这与PIP测试版本8.1.2,9.0.1,10.0.1和18.1。
要在Linux上不干扰当前目录的情况下获取输出,请使用
pip download [package] -d /tmp --no-binary :all: -v
-d
告诉pip下载应该放置文件的目录。
更好的方法是,仅使用以下脚本,并使用参数作为包名称来仅获取依赖项作为输出:
#!/bin/sh
PACKAGE=$1
pip download $PACKAGE -d /tmp --no-binary :all:-v 2>&1 \
| grep Collecting \
| cut -d' ' -f2 \
| grep -Ev "$PACKAGE(~|=|\!|>|<|$)"
也可以在这里。
回答 1
看看我的项目johnnydep!
安装:
pip install johnnydep
用法示例:
$ johnnydep requests
name summary
------------------------- ----------------------------------------------------------------------
requests Python HTTP for Humans.
├── certifi>=2017.4.17 Python package for providing Mozilla's CA Bundle.
├── chardet<3.1.0,>=3.0.2 Universal encoding detector for Python 2 and 3
├── idna<2.7,>=2.5 Internationalized Domain Names in Applications (IDNA)
└── urllib3<1.23,>=1.21.1 HTTP library with thread-safe connection pooling, file post, and more.
更复杂的树:
$ johnnydep ipython
name summary
-------------------------------- -----------------------------------------------------------------------------
ipython IPython: Productive Interactive Computing
├── appnope Disable App Nap on OS X 10.9
├── decorator Better living through Python with decorators
├── jedi>=0.10 An autocompletion tool for Python that can be used for text editors.
│ └── parso==0.1.1 A Python Parser
├── pexpect Pexpect allows easy control of interactive console applications.
│ └── ptyprocess>=0.5 Run a subprocess in a pseudo terminal
├── pickleshare Tiny 'shelve'-like database with concurrency support
├── prompt-toolkit<2.0.0,>=1.0.4 Library for building powerful interactive command lines in Python
│ ├── six>=1.9.0 Python 2 and 3 compatibility utilities
│ └── wcwidth Measures number of Terminal column cells of wide-character codes
├── pygments Pygments is a syntax highlighting package written in Python.
├── setuptools>=18.5 Easily download, build, install, upgrade, and uninstall Python packages
├── simplegeneric>0.8 Simple generic functions (similar to Python's own len(), pickle.dump(), etc.)
└── traitlets>=4.2 Traitlets Python config system
├── decorator Better living through Python with decorators
├── ipython-genutils Vestigial utilities from IPython
└── six Python 2 and 3 compatibility utilities
回答 2
仅当软件包已安装时,您才可以使用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
回答 3
注意:此答案中使用的功能于2014年弃用,并于2015年删除。请参阅适用于现代语言的其他答案
pip
。
您可以直接通过pip获得最接近的--no-install
参数:
pip install --no-install <package>
例如,这是安装Celery时的输出:
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
目录一样容易。
回答 4
该命令pip install <package> --download <path>
应当使用,如通过在@radtek评论提到的,由于作为7.0.0(2015年5月21日),–no安装被除去从pip
。这会将所需的依赖项下载到中<path>
。
回答 5
回答 6
我引用@onnovalkering的替代解决方案:
PyPi为JSON端点提供了包元数据:
>>> import requests >>> url = 'https://pypi.org/pypi/{}/json' >>> json = requests.get(url.format('pandas')).json() >>> json['info']['requires_dist'] ['numpy (>=1.9.0)', 'pytz (>=2011k)', 'python-dateutil (>=2.5.0)'] >>> json['info']['requires_python'] '>=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*'
对于特定的软件包版本,请在URL中添加一个附加的版本段:
https://pypi.org/pypi/pandas/0.22.0/json
另外,如果您使用的是conda(如@ShpielMeister所建议),则可以使用:
conda info package==X.X.X
显示信息,包括特定版本的依存关系,或:
conda info package
显示信息,包括有关该软件包所有受支持版本的依赖性。