如何pip安装最小和最大版本范围的包? [英] How to pip install a package with min and max version range?

查看:105
本文介绍了如何pip安装最小和最大版本范围的包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有任何方法可以告诉 pip,特别是在需求文件中,安装具有最低版本 (pip install package>=0.2) 和最高版本的软件包永远不应该安装(理论上的 api:pip install package<0.3).

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

我之所以这么问是因为我正在使用正在积极开发的第三方库.我希望我的 pip 要求文件指定它应该始终安装 0.5.x 分支的最新次要版本,但我不希望 pip 尝试安装任何更新的主要版本(如 0.6.x),因为API 是不同的.这很重要,因为即使 0.6.x 分支可用,开发人员仍在向 0.5.x 分支发布补丁和错误修复,所以我不想使用静态 package==0.5.9 行在我的需求文件中.

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?

推荐答案

您可以:

$ pip install "package>=0.2,<0.3"

并且 pip 将寻找最佳匹配,假设版本至少为 0.2,并且小于 0.3.

And pip will look for the best match, assuming the version is at least 0.2, and less than 0.3.

这也适用于 pip 需求文件.请参阅 PEP 440 中有关版本说明符的完整详细信息.

This also applies to pip requirements files. See the full details on version specifiers in PEP 440.

这篇关于如何pip安装最小和最大版本范围的包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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