在 requirements.txt 中,代字号等于 (~=) 是什么意思?
In requirements.txt, what does tilde equals (~=) mean?
在我正在使用的 Python 库的 requirements.txt
中,其中一个要求被指定为:
mock-django~=0.6.10
~=
是什么意思?
表示会select最新版本的包,大于等于0.6.10,但还是0.6.*版本,所以不会下载0.7.0等.如果包维护者尊重语义版本控制(声明重大更改应仅在主要版本中发生),它确保您将获得安全修复程序但保持向后兼容性。
或者,如 PEP 440 所述:
For a given release identifier V.N , the compatible release clause is approximately equivalent to the pair of comparison clauses:
>= V.N, == V.*
A compatible release clause consists of the compatible release operator ~= and a version identifier. It matches any candidate version that is expected to be compatible with the specified version.
您可以在此处阅读更多内容:https://www.python.org/dev/peps/pep-0440/#compatible-release
那就是 'compatible release' version specifier。
等同于:mock-django >= 0.6.10, == 0.6.*
,是匹配预期兼容版本的一种简洁方式。用简单的英语来说,有点像说:"I need a version of mock-django which is at least as new as 0.6.10, but not so new that it isn't compatible with it."
如果您不确定所有这些版本号的内容,快速浏览一下 PEP440 version scheme 应该可以解决您的问题!
~=表示兼容版本。不少于 0.6.10 和更高 (0.6.*)。
除了现有的答案之外,我认为还必须提及 while
~=0.6.10 means >=0.6.10, ==0.6.*
以下也是正确的
~=0.6 means >=0.6, ==0.*
PEP documentation中提到了它。
~=
Compatible release(包括预发布版和post发布版)的完整定义是:
A compatible release clause consists of the compatible release
operator ~=
and a version identifier. It matches any candidate version
that is expected to be compatible with the specified version.
The specified version identifier must be in the standard format
described in Version scheme. Local version identifiers are NOT
permitted in this version specifier.
For a given release identifier V.N
, the compatible release clause is
approximately equivalent to the pair of comparison clauses:
>= V.N, == V.*
This operator MUST NOT be used with a single segment version number such as ~=1
.
For example, the following groups of version clauses are equivalent:
~= 2.2
>= 2.2, == 2.*
~= 1.4.5
>= 1.4.5, == 1.4.*
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.*
The padding rules for release segment comparisons means that the
assumed degree of forward compatibility in a compatible release clause
can be controlled by appending additional zeros to the version
specifier:
~= 2.2.0
>= 2.2.0, == 2.2.*
~= 1.4.5.0
>= 1.4.5.0, == 1.4.5.*
在我正在使用的 Python 库的 requirements.txt
中,其中一个要求被指定为:
mock-django~=0.6.10
~=
是什么意思?
表示会select最新版本的包,大于等于0.6.10,但还是0.6.*版本,所以不会下载0.7.0等.如果包维护者尊重语义版本控制(声明重大更改应仅在主要版本中发生),它确保您将获得安全修复程序但保持向后兼容性。
或者,如 PEP 440 所述:
For a given release identifier V.N , the compatible release clause is approximately equivalent to the pair of comparison clauses:
>= V.N, == V.*
A compatible release clause consists of the compatible release operator ~= and a version identifier. It matches any candidate version that is expected to be compatible with the specified version.
您可以在此处阅读更多内容:https://www.python.org/dev/peps/pep-0440/#compatible-release
那就是 'compatible release' version specifier。
等同于:mock-django >= 0.6.10, == 0.6.*
,是匹配预期兼容版本的一种简洁方式。用简单的英语来说,有点像说:"I need a version of mock-django which is at least as new as 0.6.10, but not so new that it isn't compatible with it."
如果您不确定所有这些版本号的内容,快速浏览一下 PEP440 version scheme 应该可以解决您的问题!
~=表示兼容版本。不少于 0.6.10 和更高 (0.6.*)。
除了现有的答案之外,我认为还必须提及 while
~=0.6.10 means >=0.6.10, ==0.6.*
以下也是正确的
~=0.6 means >=0.6, ==0.*
PEP documentation中提到了它。
~=
Compatible release(包括预发布版和post发布版)的完整定义是:
A compatible release clause consists of the compatible release operator
~=
and a version identifier. It matches any candidate version that is expected to be compatible with the specified version.The specified version identifier must be in the standard format described in Version scheme. Local version identifiers are NOT permitted in this version specifier.
For a given release identifier
V.N
, the compatible release clause is approximately equivalent to the pair of comparison clauses:
>= V.N, == V.*
This operator MUST NOT be used with a single segment version number such as
~=1
.For example, the following groups of version clauses are equivalent:
~= 2.2
>= 2.2, == 2.*
~= 1.4.5
>= 1.4.5, == 1.4.*
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.*
The padding rules for release segment comparisons means that the assumed degree of forward compatibility in a compatible release clause can be controlled by appending additional zeros to the version specifier:
~= 2.2.0
>= 2.2.0, == 2.2.*
~= 1.4.5.0
>= 1.4.5.0, == 1.4.5.*