poetry add packageのオプションについて
現象
以下のpyproject.tomlの場合にdataclassesをインストールする際に
tool.poetry.dependencies
python = "^3.6"
下記エラーが発生する
SolverProblemError
The current project's Python requirement (^3.6) is not compatible with some of the required packages Python requirement:
- dataclasses requires Python >=3.6, <3.7
Because no versions of dataclasses match >0.7,<0.8
and dataclasses (0.7) requires Python >=3.6, <3.7, dataclasses is forbidden.
So, because hey depends on dataclasses (^0.7), version solving failed.
解決策
poetry add dataclasses --python ">=3.6, <3.7"
poery add のオプションにpythonのversionを参照するようにオプションにそれら情報を含めてからインストールする必要がある
ただpoetryのドキュメントを読んでもそのオプションの指定方法がわからなかったので調べた過程や結果をこちらに記す
詳細
dataclassesをインストールする場合、以下のようにする
poetry add dataclasses
dataclassesはPython 3.6のbackport用にインストールする
したがって、Dependencyを考慮すると以下のようになる
Python (^3.6 <3.7)
上記オプションをpoetry add package に考慮する必要がある
dataclasses = { version="^0.7", python="^3.6, <3.7" }
参考
https://github.com/python-poetry/poetry/issues/2386
https://python-poetry.org/docs/cli/#add
https://python-poetry.org/docs/dependency-specification/