如何在 `requirements.txt` 中包含发布候选版本 (rc) 或实际版本

How to include a release candidate (rc) OR the actual version once released in `requirements.txt`

我想在 requirements.txt 中为 tensorflow~=2.5.0 设置依赖项。在撰写本文时,tensorflow==2.5.0 尚未发布。可用的最新版本是候选发布 tensorflow==2.5.0rc3。我怎样才能简洁地告诉 pip “安装最新的 tensorflow 2.5.x 版本,包括候选版本”?

到目前为止我尝试过的:

ERROR: Could not find a version that satisfies the requirement tensorflow~=2.5.0 (from versions: 2.5.0rc0, 2.5.0rc1, 2.5.0rc2, 2.5.0rc3)
ERROR: No matching distribution found for tensorflow~=2.5.0
ERROR: Could not find a version that satisfies the requirement tensorflow>2.4.1 (from versions: 1.13.0rc1, 1.13.0rc2, 1.13.1, 1.13.2, 1.14.0rc0, 1.14.0rc1, 1.14.0, 1.15.0rc0, 1.15.0rc1, 1.15.0rc2, 1.15.0rc3, 1.15.0, 1.15.2, 1.15.3, 1.15.4, 1.15.5, 2.0.0a0, 2.0.0b0, 2.0.0b1, 2.0.0rc0, 2.0.0rc1, 2.0.0rc2, 2.0.0, 2.0.1, 2.0.2, 2.0.3, 2.0.4, 2.1.0rc0, 2.1.0rc1, 2.1.0rc2, 2.1.0, 2.1.1, 2.1.2, 2.1.3, 2.2.0rc0, 2.2.0rc1, 2.2.0rc2, 2.2.0rc3, 2.2.0rc4, 2.2.0, 2.2.1, 2.2.2, 2.3.0rc0, 2.3.0rc1, 2.3.0rc2, 2.3.0, 2.3.1, 2.3.2, 2.4.0rc0, 2.4.0rc1, 2.4.0rc2, 2.4.0rc3, 2.4.0rc4, 2.4.0, 2.4.1, 2.5.0rc0, 2.5.0rc1, 2.5.0rc2, 2.5.0rc3)
ERROR: No matching distribution found for tensorflow>2.4.1

根据 "Pre-release Versions" in the pip documentation 部分:

If a Requirement specifier includes a pre-release or development version (e.g. >=0.0.dev0) then pip will allow pre-release and development versions for that requirement. This does not include the != flag.

这个可以在命令行上测试。由于 Tensorflow 2.5.0 目前尚未发布,我们得到:

$ pip download tensorflow~=2.5.0
ERROR: Could not find a version that satisfies the requirement tensorflow~=2.5.0 (from versions: 2.5.0rc0, 2.5.0rc1, 2.5.0rc2, 2.5.0rc3)
ERROR: No matching distribution found for tensorflow~=2.5.0

但是如果我们添加预发布版本说明符:

$ pip download tensorflow~=2.5.0rc0
Collecting tensorflow~=2.5.0rc0
  Downloading tensorflow-2.5.0rc3-cp39-cp39-win_amd64.whl (422.6 MB)
  …

这将在常规版本可用后进行安装。