pip vs Poetry: CIにはどちらのPython依存管理ツールを使うか?
CIにおいて、pipとPoetryの差は、実のところ、その場限りのインストールとコミットされたlockfileの差です。
どちらもPythonの依存関係をインストールしますが、Poetryはプロジェクトモデルと本物のlockfileを加えるのに対し、pipは最小限で普遍的なままです。
| pip | Poetry | |
|---|---|---|
| Lockfile | ネイティブにはなし(pip-tools / requirements.txt を使う) | poetry.lock(組み込み) |
| 再現可能なインストール | すべて固定した場合のみ | はい、lockから |
| 依存リゾルバ | 基本的(バックトラッキング、改善中) | フルリゾルバ |
| CIでのインストール | pip install -r requirements.txt | poetry install --no-root |
| キャッシュキー | requirements.txt のハッシュ | poetry.lock のハッシュ |
CIに特化して
Poetryは最初から決定的なビルドを与えます。poetry.lockをコミットすれば、各実行が同じバージョンをインストールします。固定していないrequirements.txtを伴う素のpipは時間とともにずれ、「自分のマシンでは動く」というCIの失敗を招きます。pipは依然として最も軽量な選択肢で、シンプルなスクリプトや、ツールがpipしか説明していない場合には正しい選択です。
正しいものをキャッシュする
依存キャッシュのキーはlockfile(poetry.lock)か固定したrequirements.txtに基づけ、Poetryのvirtualenvかpipのwheelキャッシュをキャッシュしましょう。キャッシュは、どのツールを選ぶかよりも実時間に効きます。
結論
最小限の労力で再現可能なビルドが欲しい: Poetry。シンプルなプロジェクト向けに最も軽量で普遍的なツールが欲しい: すべてを固定したrequirementsを伴うpip。いずれにせよ、lockfileをコミットしてキャッシュしましょう。
関連ガイド
How to Cache Dependencies in GitHub Actions (Every Ecosystem)Cache dependencies in GitHub Actions with actions/cache - correct keys and paths for npm, yarn, pnpm, pip, Ma…
Poetry vs uv: Faster Python Dependency Management in CIPoetry vs uv for Python CI: install speed, lockfiles, and resolver performance. Why uv is often dramatically…
conda vs pip: Which for Python CI Environments?conda vs pip for Python CI: native dependencies, environment management, and speed. When conda is worth the o…