我想知道是否有任何方法可以告诉 pip,特别是在需求文件中,安装具有最低版本 (pip install package>=0.2
) 和最高版本的软件包,而最高版本永远不应该已安装(理论 API:pip install package<0.3
)。
我问这个问题是因为我正在使用正在积极开发的第三方库。我希望我的 pip 要求文件指定它应该始终安装 0.5.x 分支的最新次要版本,但我不希望 pip 尝试安装任何较新的主要版本(例如 0.6.x),因为API 不同。这很重要,因为即使 0.6.x 分支可用,开发人员仍在向 0.5.x 分支发布补丁和错误修复,因此我不想使用静态 package==0.5.9 行。
有什么办法可以做到这一点吗?
I'm wondering if there's any way to tell pip, specifically in a requirements file, to install a package with both a minimum version (pip install package>=0.2
) and a maximum version which should never be installed (theoretical api: pip install package<0.3
).
I ask because I am using a third party library that's in active development. I'd like my pip requirements file to specify that it should always install the most recent minor release of the 0.5.x branch, but I don't want pip to ever try to install any newer major versions (like 0.6.x) since the API is different. This is important because even though the 0.6.x branch is available, the devs are still releasing patches and bugfixes to the 0.5.x branch, so I don't want to use a static package==0.5.9
line in my requirements file.
Is there any way to do that?
发布评论
评论(4)
您可以这样做:
并且
pip
将寻找最佳匹配,假设版本至少为 0.2,并且小于 0.3。这也适用于 pip 需求文件。请参阅 PEP 440 中有关版本说明符的完整详细信息。
You can do:
And
pip
will look for the best match, assuming the version is at least 0.2, and less than 0.3.This also applies to pip requirements files. See the full details on version specifiers in PEP 440.
一种优雅的方法是根据 ~= 兼容释放运算符rel="noreferrer">PEP 440。在您的情况下,这相当于:
例如,如果存在以下版本,它将选择
0.5.9
:0.5.0
0.5.9
code>0.6.0
为了澄清起见,一对中的每两行是等效的:
An elegant method would be to use the
~=
compatible release operator according to PEP 440. In your case this would amount to:As an example, if the following versions exist, it would choose
0.5.9
:0.5.0
0.5.9
0.6.0
For clarification, each two lines in a pair are equivalent:
您还可以使用:
更加一致且易于阅读。
you can also use:
which is more consistent and easy to read.
nok.github.io/pipdev 是一个交互式工具,供开发人员测试已定义的版本处理说明符。
与问题相关:nok.github.io/pipdev?spec=~=0.5.0&vers=0.6
nok.github.io/pipdev is an interactive tool for developers to test defined specifiers for version handling.
Related to the question: nok.github.io/pipdev?spec=~=0.5.0&vers=0.6