LoginSignup
616
628

More than 3 years have passed since last update.

pipでアップデートするときのコマンド pip update

Last updated at Posted at 2018-11-26

こんなメモ書きの記事を多くのエンジニアのみなさんに見て頂けて光栄です。
色んなエンジニアさんと交流できればと思っていますのでよろしければfacebookやtwitterにも気軽にメッセージください。

pipでアップデートする方法関連

pipでアップデートするときよく忘れるのでメモする。
ちなみに一括アップデートはあまりやりたくないので調べはしたが試していない。
一括アップデートは↓この辺を参考。

パッケージのインストール

$ pip install <package-name>

これはさすがに忘れないけどなんとなく。

パッケージのバージョン指定インストール

$ pip install <package-name>==<version>

pip 依存関係の確認

$ pip check

No broken requirements found.

※問題なければ上記のように表示される。

依存関係に問題がある場合はこんな感じ。

wagtail 2.6.1 has requirement django-modelcluster<5.0,>=4.2, but you have django-modelcluster 5.0.

パッケージのリスト全部表示

$ pip list

Package                          Version
-------------------------------- ---------
altgraph                         0.16.1
beautifulsoup4                   4.6.0
bottle                           0.12.17
certifi                          2019.6.16
chardet                          3.0.4
coverage                         4.5.4
Django                           2.2.7
django-admin-rangefilter         0.5.1
django-bootstrap-datepicker-plus 3.0.5
django-modelcluster              4.4
django-taggit                    0.24.0
django-treebeard                 4.3
djangorestframework              3.10.2
draftjs-exporter                 2.1.6
future                           0.17.1
html5lib                         1.0.1
idna                             2.8
numpy                            1.16.4
pefile                           2019.4.18
Pillow                           6.1.0
pip                              19.3.1
pycodestyle                      2.5.0
PyInstaller                      3.5
pytz                             2019.1
pywin32-ctypes                   0.2.0
pyxel                            1.2.6
requests                         2.22.0
Rx                               3.0.0b4
setuptools                       40.8.0
six                              1.12.0
sqlparse                         0.3.0
Unidecode                        1.1.1
urllib3                          1.25.3
wagtail                          2.6.3
webencodings                     0.5.1
Willow                           1.1

アップデート必要なパッケージのリスト(これは便利)

$ pip list -o

Package             Version   Latest    Type
------------------- --------- --------- -----
beautifulsoup4      4.6.0     4.8.1     wheel
certifi             2019.6.16 2019.9.11 wheel
django-modelcluster 4.4       5.0       wheel
django-taggit       0.24.0    1.1.0     wheel
djangorestframework 3.10.2    3.10.3    wheel
draftjs-exporter    2.1.6     2.1.7     sdist
future              0.17.1    0.18.2    sdist
numpy               1.16.4    1.17.3    wheel
Pillow              6.1.0     6.2.1     wheel
pytz                2019.1    2019.3    wheel
pyxel               1.2.6     1.2.8     wheel
Rx                  3.0.0b4   3.0.1     wheel
setuptools          40.8.0    41.6.0    wheel
six                 1.12.0    1.13.0    wheel
urllib3             1.25.3    1.25.6    wheel
Willow              1.1       1.3       wheel

最新状況のパッケージのみ表示(update不要のもの)

$ pip list -u

Package                          Version
-------------------------------- ---------
altgraph                         0.16.1
bottle                           0.12.17
chardet                          3.0.4
coverage                         4.5.4
Django                           2.2.7
django-admin-rangefilter         0.5.1
django-bootstrap-datepicker-plus 3.0.5
django-treebeard                 4.3
html5lib                         1.0.1
idna                             2.8
pefile                           2019.4.18
pip                              19.3.1
pycodestyle                      2.5.0
PyInstaller                      3.5
pywin32-ctypes                   0.2.0
requests                         2.22.0
sqlparse                         0.3.0
Unidecode                        1.1.1
wagtail                          2.6.3
webencodings                     0.5.1

パッケージをパッケージ名==バージョンで表示

$ pip freeze

altgraph==0.16.1
beautifulsoup4==4.6.0
bottle==0.12.17
certifi==2019.6.16
chardet==3.0.4
coverage==4.5.4
Django==2.2.7
django-admin-rangefilter==0.5.1
django-bootstrap-datepicker-plus==3.0.5
django-modelcluster==4.4
django-taggit==0.24.0
django-treebeard==4.3
djangorestframework==3.10.2
draftjs-exporter==2.1.6
future==0.17.1
html5lib==1.0.1
idna==2.8
numpy==1.16.4
pefile==2019.4.18
Pillow==6.1.0
pycodestyle==2.5.0
PyInstaller==3.5
pytz==2019.1
pywin32-ctypes==0.2.0
pyxel==1.2.6
requests==2.22.0
Rx==3.0.0b4
six==1.12.0
sqlparse==0.3.0
Unidecode==1.1.1
urllib3==1.25.3
wagtail==2.6.3
webencodings==0.5.1
Willow==1.1

requirements.txtに出力するときに使うと便利

$ pip freeze > requirements.txt

パッケージのアップデート

$ pip install -U <package-name>

pip自体のアップデート

$ pip install -U pip

Collecting pip
  Downloading https://files.pythonhosted.org/packages/c2/d7/90f34cb0d83a6c5631cf71dfe64cc1054598c843a92b400e55675cc2ac37/pip-18.1-py2.py3-none-any.whl (1.3MB)
    100% |████████████████████████████████| 1.3MB 706kB/s
Installing collected packages: pip
  Found existing installation: pip 18.0
    Uninstalling pip-18.0:
      Successfully uninstalled pip-18.0
Successfully installed pip-18.1

requirements.txtで一括インストール

$ pip install -r requirements.txt

パッケージのアンインストール

$ pip uninstall <package-name>

パッケージ個別に詳細内容を確認(バージョンやインストール場所など)

$ pip show <package-name>

例)

$ pip show bottle

Name: bottle
Version: 0.12.17
Summary: Fast and simple WSGI-framework for small web-applications.
Home-page: http://bottlepy.org/
Author: Marcel Hellkamp
Author-email: marc@gsites.de
License: MIT
Location: c:\users\[username]\appdata\local\programs\python\python37-32\lib\site-packages
Requires:
Required-by:
616
628
3

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
616
628