#10569·poetry

使用 `poetry add` 与 `||` 运算符会导致其他诗歌命令无法继续执行

作者: rzuckerm创建于 2025年9月24日更新于 2026年8月31日
标签kind/bugarea/cliarea/core

Description

I am able to add a dependency like this: poetry add 'pytest=^4|^6'. However if I run poetry installor similar command that needs to read thepyproject.toml`, I see this error:

The requirement is invalid: Unexpected character at column 16
pytest (>=4,<5 || >=6,<7)

Similarly, if I try to add the dependency this this: poetry add 'pytest>=4,<7,!=5.*'. I get a similar error when I run something like poetry install`:

The requirement is invalid: Unexpected character at column 21
pytest (>=4,<5.dev0 || ==6.*)

Workarounds

  • Manually remove the dependency from pyproject.toml
  • Run poetry update
  • Manually add this:
    [tool.poetry.dependencies]
    pytest = "^4|^6"
  • Run poetry update

Poetry Installation Method

pip inside a virtualenv

内容来源: python-poetry/poetry