为什么Poetry没有选择我依赖的好版本?

问题描述 投票:0回答:1

我维护一个想要与 Python 3.8+ 兼容的库(因为我遵循 SemVer 并且现在不想推送主要版本),但也对 NumPy 有传递依赖。

因为 NumPy 最近放弃了对 Python 3.8 的支持,所以我在我的

pyproject.toml
中指定了应根据 Python 版本使用的 NumPy 版本:

[tool.poetry.dependencies]
python = "^3.8"
numpy = [
    { version = "<1.25", python = "3.8.*" },
    { version = "^1.25", python = "^3.9" },
]

如果我理解正确的话诗歌文档,这应该意味着:

  • 如果Python版本是3.8.*,则使用1.25以下的最新版本的NumPy;
  • 如果 Python 版本为 3.9+,则使用 1.25 到 2.0 之间的最新 NumPy 版本(感谢 caret versions)。

现在 NumPy 版本是 1.26,但运行

poetry install
仍然安装 1.25.2。 我还尝试删除锁定文件(无论如何都是 .gitignored),删除 venv 并重新运行
poetry install
,并用
>=
替换插入符号,但它继续安装 1.25.2 而不是 1.26。

我的 CI 上也出现这种情况,看来与我本地安装没有任何关系。

我的错误在哪里?

python numpy dependencies python-poetry
1个回答
0
投票

NumPy 最近改变了他们在

pyproject.toml
([1]) 中处理与 Python 兼容性的方式:

[project]
name = "numpy"
version = "1.26.1"
# ...
requires-python = ">=3.9,<3.13"

在 1.25 版本中,他们仅在 Python 上引发错误 < 3.9 and displayed a warning on Python 3.12+ in their

setup.py
[2][3]):

if sys.version_info[:2] < (3, 9):
    raise RuntimeError("Python version >= 3.9 required.")

# ...

if sys.version_info >= (3, 12):
    fmt = "NumPy {} may not yet support Python {}.{}."
    warnings.warn(
        fmt.format(VERSION, *sys.version_info[:2]),
        RuntimeWarning)
    del fmt

因此,为了让 Poetry 选择 Python 3.9+ 上的 NumPy 的最新版本,我们需要告诉它我们还不支持 3.13 版本:

[tool.poetry.dependencies]
python = "^3.8"
numpy = [
    { version = "<1.25", python = "3.8.*" },
-   { version = "^1.25", python = "^3.9" },
+   { version = "^1.25", python = ">=3.9,<3.13" },
]
© www.soinside.com 2019 - 2024. All rights reserved.