Yoh*_*hei 7 python python-poetry
我用 Poetry 创建了一个 python 项目“foo”。这是以下内容pyproject.toml:
[tool.poetry]
name = "bar"
version = "0.1.0"
description = ""
[tool.poetry.dependencies]
python = ">=3.5"
[tool.poetry.dev-dependencies]
[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
Run Code Online (Sandbox Code Playgroud)
该包兼容Python3.5。我想要黑色格式化程序,它与Python3.5不兼容。我觉得使用Python>=3.6开发是没有问题的,但是无法安装black formatter:
[tool.poetry]
name = "bar"
version = "0.1.0"
description = ""
[tool.poetry.dependencies]
python = ">=3.5"
[tool.poetry.dev-dependencies]
[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
Run Code Online (Sandbox Code Playgroud)
所以我直接安装了黑色pip:
$ poetry add black --dev
[SolverProblemError]
The current project's Python requirement (>=3.5) is not compatible with some of the required packages Python requirement:
- black requires Python >=3.6
Because no versions of black match >19.10b0,<20.0
and black (19.10b0) requires Python >=3.6, black is forbidden.
So, because bar depends on black (^19.10b0), version solving failed.
Run Code Online (Sandbox Code Playgroud)
这种方式不太适合我。我想black通过诗歌来安装。
我应该怎么做?(我不想修改依赖项python>=3.6)
看起来有点晚了,但实际上你可以做你想做的,即使黑色仅支持 Python >=3.6.2
在 pyproject.toml 中,您可以定义受限制的依赖关系,如https://python-poetry.org/docs/dependency-specification/#python-restricted-dependencies中所述
[tool.poetry.dependencies]
python = ">=3.5"
[tool.poetry.dev-dependencies]
black = {version = "^21.7b0", python = ">=3.6.2"}
Run Code Online (Sandbox Code Playgroud)
Poetry 不会抱怨,你也不会有任何问题,因为它是一个开发依赖项。