君たちは永遠にそいつらより若い

技術と音楽と日々のこと。

pipのlistとfreezeの違い



諸事情で最近Pythonってます。

現在インストールされているパッケージをpipで表示する際、listfreezeをどっちを使うか、違いが分かりにくかったので解説。

結論から先に行っておくと、今インストール済みのパッケージを確認したいだけならどっちでもいい。けど、freezeの方がよく使うので、こっちで覚えておいたら良いと思います。

pip list [options]

Description:
  List installed packages, including editables.

List Options:
  -o, --outdated              List outdated packages (excluding editables)
  -u, --uptodate              List uptodate packages (excluding editables)
  -e, --editable              List editable projects.
  -l, --local                 If in a virtualenv that has global access, do not list globally-installed packages.
  --pre                       Include pre-release and development versions. By default, pip only finds stable versions.
  • 開発版を含む、インストール済みのパッケージリストの表示(直訳)
  • 更新可能なバージョン、最新バージョン、開発バージョン(editable install)などの切り口で表示可能
  • pip自身や、setuptoolsなどのパッケージ管理ツールも一緒に表示される
$ pip list
closure-linter (2.3.13)
pip (1.5.6)
python-gflags (2.0)
setuptools (7.0)
vboxapi (1.0)
virtualenv (12.0.7)
wsgiref (0.1.2)

pip freeze [options]

Description:
  Output installed packages in requirements format.

Freeze Options:
  -r, --requirement <file>    Use the order in the given requirements file and it's comments when generating output.
  -f, --find-links <url>      URL for finding packages, which will be added to the output.
  -l, --local                 If in a virtualenv that has global access, do not output globally-installed packages.
  • インストール済みのパッケージを必要とされるフォーマットで出力(直訳)
  • 出力したパッケージリストをテキストファイルで保存しておくと、install -rを使ってパッケージを全部インストールできる(この用途でよく使う)
$ pip freeze > packages.txt
$ pip install -r packages.txt
  • pip自身や、setuptoolsなどのパッケージ管理ツールは表示されない(ので、listと結果が違う)
$ pip freeze
closure-linter==2.3.13
python-gflags==2.0
vboxapi==1.0
virtualenv==12.0.7
wsgiref==0.1.2

おまけ

各パッケージの詳細情報を知りたいときは、pip showです。

$ pip show virtualenv
---
Name: virtualenv
Version: 12.0.7
Location: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
Requires: