使用'pre'选项时,pip不匹配预发布版本

2024-05-23 16:58:56 发布

您现在位置:Python中文网/ 问答频道 /正文

假设您已经发布了两个预发行版:

 package 0.0.1.dev0
 package 0.0.2.dev0

我在setup.py中的install_requires部分指出:

[
    'package>=0.0.2,<1.0.0'
]

现在,当我运行pip install . --upgrade --pre时,我得到一个错误:

ERROR: Could not find a version that satisfies the requirement package<1.0.0,>=0.0.2 (from versions: 0.0.1.dev0, 0.0.2.dev0) ERROR: No matching distribution found for package<1.0.0,>=0.0.2

我做错了什么?--pre标志不是应该告诉pip匹配预发布版本吗


Tags: installpippypackageversion错误setupnot
1条回答
网友
1楼 · 发布于 2024-05-23 16:58:56

摘要

pip pre选项指示pip包含潜在的匹配预发布版本和开发版本,但它不会更改版本匹配的语义

由于预发行版0.0.2.dev0比稳定发行版0.0.2旧,因此pip在搜索至少与稳定发行版0.0.2一样新的包时会正确报告错误

说明

混淆的关键点是关于pip pre选项,它被记录为:

pre
Include pre-release and development versions. By default, pip only finds stable versions.

问题的前提是 pre选项应该更改包版本匹配语义,以便在与稳定版本匹配时忽略预发布版本后缀

进一步澄清,考虑兼容释放操作符<强> ^ {< CD7>}。PEP 440第Compatible release节部分规定:

For a given release identifier V.N, the compatible release clause is approximately equivalent to the pair of comparison clauses:

>= V.N, == V.*

...

If a pre-release, post-release or developmental release is named in a compatible release clause as V.N.suffix, then the suffix is ignored when determining the required prefix match:

~= 2.2.post3 = 2.2.post3, == 2.*

~= 1.4.5a4 = 1.4.5a4, == 1.4.*

这个例子清楚地表明后缀被忽略

以下要求与0.0.2.dev0不匹配:

install_requires=['package~=0.0.2']  # ERROR: ResolutionImpossible

然而,这个例子确实匹配稳定释放0.0.2

install_requires=['package~=0.0.2.dev0']  # OK - suffix ignored

相关问题 更多 >