使用`--pre`选项时,pip不匹配预发布版本 [英] Pre-release versions are not matched by pip when using the `--pre` option

查看:67
本文介绍了使用`--pre`选项时,pip不匹配预发布版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设您发布了两个预发布版本:

 包 0.0.1.dev0包 0.0.2.dev0

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

<预><代码>['包>=0.0.2,<1.0.0']

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

<块引用>

错误:找不到满足要求的版本包<1.0.0,>=0.0.2(来自版本:0.0.1.dev0、0.0.2.dev0)错误:找不到包<1.0.0,>=0.0.2

的匹配发行版

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

解决方案

总结

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

由于预发行版 0.0.2.dev0 早于稳定发行版 0.0.2,因此 pip 在搜索至少为新的稳定版本 0.0.2.

说明

混淆的关键点在于 pip --pre 选项,记录为:

<块引用>

--pre
包括预发布和开发版本.默认情况下,pip 只查找稳定版本.

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

为了进一步澄清,请考虑兼容发布运算符 ~=.PEP 440 部分 兼容版本,部分说明:

<块引用>

对于给定的发布标识符V.N,兼容的发布子句大约相当于一对比较子句:

>= V.N, == V.*

...

如果在兼容发布条款中将预发布、发布后或开发版本命名为 V.N.suffix,则在确定所需的前缀匹配时忽略后缀:

~= 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'] # 错误:ResolutionImpossible

而这个例子确实匹配稳定版本0.0.2:

install_requires=['package~=0.0.2.dev0'] # OK - 忽略后缀

Imagine you have published two pre-releases:

 package 0.0.1.dev0
 package 0.0.2.dev0

My install_requires section in setup.py states:

[
    'package>=0.0.2,<1.0.0'
]

Now, when i run pip install . --upgrade --pre I get an error:

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

What am I doing wrong? Isn't the --pre flag supposed to tell pip to match pre-release versions?

解决方案

Summary

The pip --pre option directs pip to include potential matching pre-release and development versions, but it does not change the semantics of version matching.

Since pre-release 0.0.2.dev0 is older than stable release 0.0.2, pip correctly reports an error when searching for a package that is at least as new as stable release 0.0.2.

Explanation

The key point of confusion is around the pip --pre option, which is documented as:

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

The premise of the question is that the --pre option should change the package-version-matching semantics such that pre-release version suffixes would be ignored when matching against stable versions.

To further clarify, consider the compatible release operator ~=. PEP 440 section Compatible release, states in part:

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.*

This example makes it clear that the suffix is ignored.

The following requirement does not match 0.0.2.dev0:

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

Whereas this example does match stable release 0.0.2:

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

这篇关于使用`--pre`选项时,pip不匹配预发布版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆