132

在不进行安装的情况下,我想快速查看所有pip install要安装的软件包。

4

10 回答 10

107

这是使用 pip 版本8.1.29.0.110.0.118.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(~|=|\!|>|<|$)"

也可以在这里找到

于 2016-07-22T17:09:09.323 回答
106

看看我的项目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
于 2018-03-25T03:45:14.777 回答
22

当且仅当软件包已安装时,您可以使用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
于 2015-07-30T08:39:46.867 回答
16

注意:此答案中使用的功能已于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目录一样简单。

于 2012-06-21T23:36:53.747 回答
3

我引用了@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

显示信息,包括有关该软件包所有受支持版本的依赖关系。

于 2019-09-28T14:10:52.400 回答
0

使用pipdeptree ( pip install pipdeptree)。需要安装包。

$ pipdeptree -p pandas
pandas==1.2.2
  - numpy [required: >=1.16.5, installed: 1.19.5]
  - python-dateutil [required: >=2.7.3, installed: 2.8.1]
    - six [required: >=1.5, installed: 1.15.0]
  - pytz [required: >=2017.3, installed: 2021.1]

使用johnnydep ( pip install johnnydep)。速度较慢,因为它会下载软件包的轮子。

$ johnnydep pandas
2021-06-09 11:01:21 [info     ] init johnnydist                [johnnydep.lib] dist=pandas parent=None
2021-06-09 11:01:22 [info     ] init johnnydist                [johnnydep.lib] dist=numpy>=1.16.5 parent=pandas
2021-06-09 11:01:22 [info     ] init johnnydist                [johnnydep.lib] dist=python-dateutil>=2.7.3 parent=pandas
2021-06-09 11:01:23 [info     ] init johnnydist                [johnnydep.lib] dist=pytz>=2017.3 parent=pandas
2021-06-09 11:01:23 [info     ] init johnnydist                [johnnydep.lib] dist=six>=1.5 parent=python-dateutil>=2.7.3
name                        summary
--------------------------  -----------------------------------------------------------------------
pandas                      Powerful data structures for data analysis, time series, and statistics
├── numpy>=1.16.5           NumPy is the fundamental package for array computing with Python.
├── python-dateutil>=2.7.3  Extensions to the standard Python datetime module
│   └── six>=1.5            Python 2 and 3 compatibility utilities
└── pytz>=2017.3            World timezone definitions, modern and historical
于 2021-06-09T10:49:56.423 回答
0

我认为这些答案已经过时,现在有更好的解决方案。原帖在这里:

要为您的orrequirements.txt中列出的包生成,您需要安装.install_requiressetup.cfgsetup.pypip-tools

pip install pip-tools
pip-compile

要生成包含在for和requirements.txt下指定的包的文件:extras_requirestestsdev

pip-compile --extra tests --extra devrequirements.txt file with packages listed under

此外,您还可以使用requirements.in文件代替setup.cfgsetup.py列出您的要求。

pip-compile requirements.in
于 2021-08-06T18:57:16.417 回答
0

只是关于如何johnnydep从 Python 而不是 CLI 调用的附录:

import sys, johnnydep.cli
sys.argv = ["", "pandas"]
johnnydep.cli.main()
于 2022-03-03T10:45:55.170 回答
-1

另一种选择是使用与此类似的帮助脚本,它使用pip.req.parse_requirementsAPI 来解析requirements.txt文件并distutils.core.setup替换来解析setup.py文件。

于 2017-06-16T10:05:13.263 回答
-1

正如@radtek 评论中提到的那样,应该使用该命令pip install <package> --download <path>,因为从 7.0.0 (2015-05-21) 开始, --no- install已从pip. 这会将所需的依赖项下载到<path>.

于 2015-11-10T14:36:05.623 回答