IT技術で仕事を減らしたい!

ITエンジニアのメモ+α

Python Poetry pyinstallerのインストールエラー

どうも、nippa です。

poetry で pyinstaller をインストールしようとした際にエラーが出ました。

他のパッケージでも起こりうることなので、その解決方法をまとめておきます。

環境

  • macOS 11.6
  • poetry 1.1.14
  • pyinstaller 5.3

インストールのエラー内容

まずpoetry initで poetry の環境を生成しました。

poetry の初期設定後、poetry add pyinstallerを実行してインストールしようとした際に、以下のようなエラーが発生しました。

Using version ^5.3 for pyinstaller

Updating dependencies
Resolving dependencies... (0.0s)

  SolverProblemError

  The current project's Python requirement (>=3.11,<4.0) is not compatible with some of the required packages Python requirement:
    - pyinstaller requires Python <3.11,>=3.7, so it will not be satisfied for Python >=3.11,<4.0

  Because no versions of pyinstaller match >5.3,<6.0
   and pyinstaller (5.3) requires Python <3.11,>=3.7, pyinstaller is forbidden.
  So, because blog-pyinstaller depends on pyinstaller (^5.3), version solving failed.

  at ~/.poetry/lib/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 pyinstaller, a possible solution would be to set the `python` property to "<empty>"

    https://python-poetry.org/docs/dependency-specification/#python-restricted-dependencies,
    https://python-poetry.org/docs/dependency-specification/#using-environment-markers

原因は、pyinstaller が要求する python のバージョン <3.11,>=3.7poetry initで設定した python のバージョンが合わないことです。

pyinsaller の配布ページにもありますが、対応している python のバージョンが、python 3.10 までであるので、3.11 が対応していないです。

解決方法

pyproject.toml の python のバージョン指定を適切に修正することで解決可能です。

# 修正前
[tool.poetry.dependencies]
python = "^3.9"

# 修正後
[tool.poetry.dependencies]
python = "^3.9,<3.11"

python 3.11 には対応していないという意味の<3.11を追加して上げると、インストール可能になります。

poetry のバージョンの書き方

poetry でのバージョン指定方法は、以下のような形でかけます。

python 3.7 から 3.10 までの場合、以下のようになります。

python = ">=3.7,<3.11"

python 3.9 だけの場合、以下の通りです。

python = "^3.9"

感想

今回 pyinstaller のインストール時にエラーが出ましたが、他のパッケージ、ライブラリでも起こりうるものなので、内容を調べてまとめました。

エラーに困っている人の役にたてればと思います。

ではでは、また次回。