Mat*_*lke 16 python scipy dependency-management python-3.x python-poetry
我在将依赖项安装到我的 Poetry 项目中时遇到问题。如果我运行(如https://python-poetry.org/docs/basic-usage/poetry new中所述),我可以创建一个新项目:
$ poetry new scipy-test\nCreated package scipy_test in scipy-test\nRun Code Online (Sandbox Code Playgroud)\n删除本次复制不需要的一些文件后,我的项目结构如下所示:
\n$ tree .\n.\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 pyproject.toml\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 scipy_test\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 __init__.py\n\n1 directory, 2 files\nRun Code Online (Sandbox Code Playgroud)\n我的pyproject.toml文件如下所示:
[tool.poetry]\nname = "scipy-test"\nversion = "0.1.0"\ndescription = ""\nauthors = ["Your Name <you@example.com>"]\n\n[tool.poetry.dependencies]\npython = "^3.9"\n\n[tool.poetry.dev-dependencies]\npytest = "^5.2"\n\n[build-system]\nrequires = ["poetry-core>=1.0.0"]\nbuild-backend = "poetry.core.masonry.api"\nRun Code Online (Sandbox Code Playgroud)\n当我运行时poetry add scipy,它会尝试安装最新版本的 SciPy,目前是 1.8.1。我收到以下错误:
$ poetry add scipy\nCreating virtualenv scipy-test-4EDXm154-py3.9 in /home/mattwelke/.cache/pypoetry/virtualenvs\nUsing version ^1.8.1 for scipy\n\nUpdating dependencies\nResolving dependencies... (0.1s)\n\n SolverProblemError\n\n The current project\'s Python requirement (>=3.9,<4.0) is not compatible with some of the required packages Python requirement:\n - scipy requires Python >=3.8,<3.11, so it will not be satisfied for Python >=3.11,<4.0\n \n Because no versions of scipy match >1.8.1,<2.0.0\n and scipy (1.8.1) requires Python >=3.8,<3.11, scipy is forbidden.\n So, because scipy-test depends on scipy (^1.8.1), version solving failed.\n\n at ~/.local/share/pypoetry/venv/lib/python3.9/site-packages/poetry/puzzle/solver.py:241 in _solve\n 237\xe2\x94\x82 packages = result.packages\n 238\xe2\x94\x82 except OverrideNeeded as e:\n 239\xe2\x94\x82 return self.solve_in_compatibility_mode(e.overrides, use_latest=use_latest)\n 240\xe2\x94\x82 except SolveFailure as e:\n \xe2\x86\x92 241\xe2\x94\x82 raise SolverProblemError(e)\n 242\xe2\x94\x82 \n 243\xe2\x94\x82 results = dict(\n 244\xe2\x94\x82 depth_first_search(\n 245\xe2\x94\x82 PackageNode(self._package, packages), aggregate_package_nodes\n\n \xe2\x80\xa2 Check your dependencies Python requirement: The Python requirement can be specified via the `python` or `markers` properties\n \n For scipy, a possible solution would be to set the `python` property to ">=3.9,<3.11"\n\n https://python-poetry.org/docs/dependency-specification/#python-restricted-dependencies,\n https://python-poetry.org/docs/dependency-specification/#using-environment-markers\nRun Code Online (Sandbox Code Playgroud)\n我将文件python = "^3.9"中的这一行解释pyproject.toml为“该项目意味着使用 Python 3.9(任何补丁版本)运行”。我将包的 Python 要求“>=3.8,<3.11”解释为“此库需要 Python 3.8、3.9 或 Python 3.10 才能使用它”。因此,如果我把这两件事放在一起,在我看来它们应该是兼容的。
错误消息确实包含帮助我解决问题的提示。它说:
\nFor scipy, a possible solution would be to set the `python` property to ">=3.8,<3.11"\nRun Code Online (Sandbox Code Playgroud)\n我同意这可以解决问题。这将使我的 Poetry 项目的 Python 版本与依赖项的 Python 要求完全匹配。我发现如果我以pyproject.toml这种方式更改文件,我就能够安装依赖项。
但我不想让我的项目使用 Python 3.8 执行。我想将其 Python 版本设置为我实际使用的最新版本。所以我的首选版本实际上是“^3.10”(如果我上面描述的理解是正确的),因为这应该意味着“你必须使用Python 3.10的任何补丁版本来运行它”。
\n如果我将该行更改为python = "^3.10",我会收到与之前相同类型的错误,除了错误消息中的提示提到版本 3.10 而不是 3.8:
For scipy, a possible solution would be to set the `python` property to ">=3.10,<3.11"\nRun Code Online (Sandbox Code Playgroud)\n如果我使用这个值,它会再次工作,允许我安装依赖项。这次,看起来它根据需要将我的项目限制为仅与 3.10 兼容。但看起来有点冗长。我仍然不明白为什么将其设置为“^3.9”(或“^3.10”)不起作用。
\n我在这里缺少什么吗?如果是这样,我将如何更改我的pyproject.toml文件以使其与我想要添加到项目中的依赖项兼容?
wkl*_*wkl 29
您指定的插入符要求...
[tool.poetry.dependencies]
python = "^3.9"
Run Code Online (Sandbox Code Playgroud)
...意味着“此 Python 代码具有兼容性3.9 <= python_version < 4”(^根据您指定版本的方式,使用语义版本控制进行不同的限制)。
这是比您的依赖项指定的更广泛的约束scipy,因为它声明仅兼容最高3.8 <= python_version < 3.11.
To poetry,scipy不满足您的约束,因为如果python3.11现在就退出,您的依赖约束会声明您的代码支持该 Python 版本,而scipy's 约束会说它不支持。
对于你来说,你可能只想要一个范围之类的东西来匹配类似 's 的东西scipy(或者缩小你的范围以适应scipy's 之类的东西)。
[tool.poetry.dependencies]
python = ">=3.10, <3.11"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
32021 次 |
| 最近记录: |