给定可以与pip一起安装的Python包的名称,是否有任何方法可以找到pip可以安装的所有可能版本的列表?现在是反复试验。

我正在尝试为第三方库安装一个版本,但最新版本太新了,有向后不兼容的更改。因此,我希望以某种方式获得pip所知道的所有版本的列表,以便我可以测试它们。


当前回答

https://pypi.python.org/pypi/Django/—适用于那些维护者选择显示所有包的包 https://pypi.python.org/simple/pip/ -无论如何都应该做到(列出所有链接)

其他回答

要找到所有可用的(甚至不兼容的)版本,使用pip >= 21.x的-vv标志。

pip install sklearn== --dry-run -vv

不兼容的版本将在日志中如下所示:

Skipping link: none of the wheel's tags (cp27-cp27m-win32) are compatible

我想出了一个非常简单的bash脚本。感谢jq的作者。

#!/bin/bash
set -e

PACKAGE_JSON_URL="https://pypi.org/pypi/${1}/json"

curl -L -s "$PACKAGE_JSON_URL" | jq  -r '.releases | keys | .[]' | sort -V

更新: 添加按版本号排序的功能。 添加-L跟随重定向。

您可以尝试安装不存在的软件包版本。然后pip将列出可用的版本

pip install hell==99999
ERROR: Could not find a version that satisfies the requirement hell==99999
(from versions: 0.1.0, 0.2.0, 0.2.1, 0.2.2, 0.2.3, 0.2.4, 0.3.0,
0.3.1, 0.3.2, 0.3.3, 0.3.4, 0.4.0, 0.4.1)
ERROR: No matching distribution found for hell==99999

我通常运行pip install packagename==somerandomstring。这将返回一个错误,提示无法找到满足packagename==somerandomstring要求的版本,与此错误一起,pip还将列出服务器上可用的版本。

e.g.

$ pip install flask==aksjflashd
Collecting flask==aksjflashd
  Could not find a version that satisfies the requirement flask==aksjflashd 
(from versions: 0.1, 0.2, 0.3, 0.3.1, 0.4, 0.5, 0.5.1, 0.5.2, 0.6, 0.6.1, 0.7, 0.7.1, 0.7.2, 0.8, 0.8.1, 0.9, 0.10, 0.10.1, 0.11, 0.11.1, 0.12, 0.12.1, 
0.12.2, 0.12.3, 0.12.4, 0.12.5, 1.0, 1.0.1, 1.0.2, 1.0.3, 1.0.4, 1.1.0, 1.1.1, 1.1.2)
No matching distribution found for flask==aksjflashd
$

如果像'aksjflashd'这样的随机字符串被证明是实际的包版本,你必须非常不幸!

当然,您也可以在pip download中使用这个技巧。

对于pip >= 21.2使用:

pip index versions pylibmc

注意,这个命令是实验性的,将来可能会改变!

对于pip >= 21.1使用:

pip install pylibmc==

对于pip >= 20.3使用:

pip install --use-deprecated=legacy-resolver pylibmc==

对于pip >= 9.0使用:

$ pip install pylibmc==
Collecting pylibmc==
  Could not find a version that satisfies the requirement pylibmc== (from 
  versions: 0.2, 0.3, 0.4, 0.5.1, 0.5.2, 0.5.3, 0.5.4, 0.5.5, 0.5, 0.6.1, 0.6, 
  0.7.1, 0.7.2, 0.7.3, 0.7.4, 0.7, 0.8.1, 0.8.2, 0.8, 0.9.1, 0.9.2, 0.9, 
  1.0-alpha, 1.0-beta, 1.0, 1.1.1, 1.1, 1.2.0, 1.2.1, 1.2.2, 1.2.3, 1.3.0)
No matching distribution found for pylibmc==

可用的版本将在不实际下载或安装任何软件包的情况下打印出来。

对于pip < 9.0使用:

pip install pylibmc==blork

其中,block可以是任何不是有效版本号的字符串。