8
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

はじめに

Pythonのパッケージ管理、選択肢が多すぎる。

pip, pip-tools, pipenv, poetry, pdm, uv ← NEW!

結局どれを使えばいいのか、最適解を紹介する。

結論(先に言う)

ユースケース 推奨ツール
超シンプルなスクリプト pip
チーム開発・ライブラリ開発 poetry
爆速が欲しい uv
2025年以降 uv一択になりそう

pip - 標準だけど機能不足

# インストール
pip install requests

# requirements.txt から
pip install -r requirements.txt

# 書き出し
pip freeze > requirements.txt

問題点

# pip freeze の結果
certifi==2024.2.2
charset-normalizer==3.3.2
idna==3.6
requests==2.31.0
urllib3==2.2.0
  • どれが直接依存でどれが間接依存かわからない
  • バージョン固定が手動
  • 仮想環境管理は別(venv)

poetry - 現在のデファクト

インストール

# Windows (PowerShell)
(Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | python -

# macOS/Linux
curl -sSL https://install.python-poetry.org | python3 -

基本コマンド

# プロジェクト作成
poetry new my-project

# 既存プロジェクトで初期化
poetry init

# パッケージ追加
poetry add requests
poetry add pytest --group dev

# インストール
poetry install

# 実行
poetry run python main.py

# シェル
poetry shell

pyproject.toml

[tool.poetry]
name = "my-project"
version = "0.1.0"
description = ""
authors = ["Your Name <you@example.com>"]

[tool.poetry.dependencies]
python = "^3.11"
requests = "^2.31.0"

[tool.poetry.group.dev.dependencies]
pytest = "^8.0.0"
mypy = "^1.8.0"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

poetry.lock

依存関係を完全に固定:

[[package]]
name = "requests"
version = "2.31.0"
description = "Python HTTP for Humans."

[package.dependencies]
certifi = ">=2017.4.17"
charset-normalizer = ">=2,<4"
idna = ">=2.5,<4"
urllib3 = ">=1.21.1,<3"

メリット

  • ✅ 依存関係の解決が賢い
  • ✅ pyproject.toml で一元管理
  • ✅ 仮想環境も自動管理
  • ✅ ライブラリ公開が簡単

デメリット

  • 遅い(依存解決に時間がかかる)
  • ❌ インストールがやや面倒

uv - Rustで爆速

uv は Astral 社(Ruff の開発元)による超高速パッケージマネージャ。

インストール

# Windows (PowerShell)
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"

# macOS/Linux
curl -LsSf https://astral.sh/uv/install.sh | sh

# pip でも
pip install uv

基本コマンド

# pip互換(超高速)
uv pip install requests
uv pip install -r requirements.txt

# プロジェクト管理(poetry互換)
uv init my-project
uv add requests
uv add pytest --dev
uv sync
uv run python main.py

# Python自体のインストールも!
uv python install 3.12

速度比較

パッケージインストール速度(Django + 依存関係)

pip:    45.3秒
poetry: 32.1秒
uv:      2.8秒  ← 10-20倍速い!

pyproject.toml(uv形式)

[project]
name = "my-project"
version = "0.1.0"
requires-python = ">=3.11"
dependencies = [
    "requests>=2.31.0",
]

[tool.uv]
dev-dependencies = [
    "pytest>=8.0.0",
    "mypy>=1.8.0",
]

メリット

  • 爆速(Rust製)
  • ✅ pip互換モードあり
  • ✅ Python自体も管理できる
  • ✅ pyproject.toml 対応

デメリット

  • ❌ まだ新しい(2024年登場)
  • ❌ エコシステムがpoetryほど成熟してない

比較表

機能 pip poetry uv
速度 遅い 普通 爆速
依存解決 なし
ロックファイル なし
仮想環境管理 別途
pyproject.toml 部分的
ライブラリ公開 別途 開発中
学習コスト

実際のワークフロー

poetry の場合

# 新規プロジェクト
poetry new my-app
cd my-app

# パッケージ追加
poetry add fastapi uvicorn
poetry add pytest black mypy --group dev

# 開発
poetry run uvicorn main:app --reload

# テスト
poetry run pytest

uv の場合

# 新規プロジェクト
uv init my-app
cd my-app

# パッケージ追加
uv add fastapi uvicorn
uv add pytest black mypy --dev

# 開発
uv run uvicorn main:app --reload

# テスト
uv run pytest

ほぼ同じ!移行は簡単。


移行ガイド

pip → poetry

# 1. poetry 初期化
poetry init

# 2. requirements.txt から追加
cat requirements.txt | xargs poetry add

# 3. requirements.txt は削除(任意)

poetry → uv

# uv は poetry.lock を読める!
uv sync

2026年の予想

  1. uv がデファクトになる

    • 速度は正義
    • Astral 社の開発力
  2. poetry は安定運用向け

    • 成熟したエコシステム
    • 保守的なチームに人気
  3. pip は消えない

    • 標準ライブラリに近い存在
    • CI/CD での軽量用途

まとめ

選択 理由
初心者 まず pip で慣れる
チーム開発 poetry(実績あり)
新規プロジェクト uv を試す価値あり
速度重視 uv 一択
# 2025年末のおすすめ
pip install uv
uv init my-new-project
uv add requests
uv run python main.py
8
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?