我有一个问题,在我的诗歌项目安装依赖关系。如果我运行poetry new
(如https://python-poetry.org/docs/basic-usage/中所述),我可以创建一个新项目:
$ poetry new scipy-test
Created package scipy_test in scipy-test
在删除一些不需要的文件后,我的项目结构如下所示:
$ tree .
.
├── pyproject.toml
└── scipy_test
└── __init__.py
1 directory, 2 files
我的pyproject.toml
文件如下所示:
[tool.poetry]
name = "scipy-test"
version = "0.1.0"
description = ""
authors = ["Your Name <you@example.com>"]
[tool.poetry.dependencies]
python = "^3.9"
[tool.poetry.dev-dependencies]
pytest = "^5.2"
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
当我运行poetry add scipy
时,它试图安装SciPy的最新版本,现在的版本是1.8.1。我得到以下错误:
$ poetry add scipy
Creating virtualenv scipy-test-4EDXm154-py3.9 in /home/mattwelke/.cache/pypoetry/virtualenvs
Using version ^1.8.1 for scipy
Updating dependencies
Resolving dependencies... (0.1s)
SolverProblemError
The current project's Python requirement (>=3.9,<4.0) is not compatible with some of the required packages Python requirement:
- scipy requires Python >=3.8,<3.11, so it will not be satisfied for Python >=3.11,<4.0
Because no versions of scipy match >1.8.1,<2.0.0
and scipy (1.8.1) requires Python >=3.8,<3.11, scipy is forbidden.
So, because scipy-test depends on scipy (^1.8.1), version solving failed.
at ~/.local/share/pypoetry/venv/lib/python3.9/site-packages/poetry/puzzle/solver.py:241 in _solve
237│ packages = result.packages
238│ except OverrideNeeded as e:
239│ return self.solve_in_compatibility_mode(e.overrides, use_latest=use_latest)
240│ except SolveFailure as e:
→ 241│ raise SolverProblemError(e)
242│
243│ results = dict(
244│ depth_first_search(
245│ PackageNode(self._package, packages), aggregate_package_nodes
• Check your dependencies Python requirement: The Python requirement can be specified via the `python` or `markers` properties
For scipy, a possible solution would be to set the `python` property to ">=3.9,<3.11"
https://python-poetry.org/docs/dependency-specification/#python-restricted-dependencies,
https://python-poetry.org/docs/dependency-specification/#using-environment-markers
我将pyproject.toml
文件中的行pyproject.toml
解释为“这个项目意味着运行Python3.9(任何补丁版本)”。我将包的Python需求">=3.8,<3.11“解释为”这个库需要Python3.8、3.9或Python3.10才能使用它“。所以,如果我把这两件事放在一起,在我看来,它们应该是相互兼容的。
错误信息确实包含了帮助我解决它的提示。上面写着:
For scipy, a possible solution would be to set the `python` property to ">=3.8,<3.11"
我同意这样可以解决这个问题。它将使我的诗歌项目的Python版本完全符合Python依赖的要求。我发现,如果我以这种方式更改了我的pyproject.toml
文件,我就能够安装这个依赖项。
但是我不想让我的项目使用Python3.8来执行。我想将它的Python版本设置为我实际使用的最新版本。所以我喜欢的版本实际上是"^ 3.10“(如果上面描述的理解是正确的),因为这应该意味着”您必须使用Python 3.10的任何补丁版本来运行它“。
如果将行更改为python = "^3.10"
,则会得到与前面相同的错误,除了错误消息中的提示提到版本3.10而不是3.8:
For scipy, a possible solution would be to set the `python` property to ">=3.10,<3.11"
如果我使用此值,它将再次工作,允许我安装该依赖项。而这一次,它似乎限制了我的项目只与3.10兼容,如所需。但看上去有点冗长。我仍然不明白为什么把它设置为"^3.9“(或"^3.10")不起作用。
这里有什么东西我遗漏了吗?如果是这样的话,我将如何更改我的pyproject.toml
文件以使它与我想要添加到我的项目中的这个依赖项兼容?
发布于 2022-07-26 00:52:20
您指定的插入符号要求..。
[tool.poetry.dependencies]
python = "^3.9"
...means“这个Python代码具有3.9 <= python_version < 4
的兼容性”(^
根据您使用语义版本控制如何指定版本来对其进行不同的限制)。
这是一个比依赖scipy
所指定的更广泛的约束,因为它只声称兼容到3.8 <= python_version < 3.11
。
对于poetry
,scipy
不满足您的约束,因为如果python3.11
现在退出,则依赖约束要求您的代码支持那个python3.11
版本,而scipy
的约束则表示它不支持。
对你来说,你可能只想要一个像scipy
那样的范围(或者缩小你的范围以适应scipy
的范围)。
[tool.poetry.dependencies]
python = ">=3.10, <3.11"
https://stackoverflow.com/questions/73116647
复制相似问题