Help us understand the problem. What is going on with this article?

【Python】pip installしたパッケージの一括アップグレード

More than 1 year has passed since last update.

目的

pip installしたパッケージを一括アップグレードしたい。

方法

コマンドプロンプトでもなんでもいいので、以下のワンライナーを実行してください。
環境によっては管理者権限で実行する必要があります。

$ python -c "import sys;from subprocess import call,check_output;p=[sys.executable,'-m','pip'];[call(p+['install','-U',n.split('=')[0]])for n in['pip']+check_output(p+['freeze']).decode().splitlines()]"

補足

パッケージ間の依存関係を無視して一括アップグレードするので、依存関係が壊れる可能性があります。
アップグレード後は念の為、依存関係が破損していないかチェックしておきましょう。

$ python -m pip check

問題がなければ No broken requirements found. と出力されます。
問題があった場合は以下のコマンドで修正できる場合もあります。

$ python -c "import sys;import subprocess as s;p=[sys.executable,'-m','pip'];[s.call(p+['install',n[:-1]])for n in s.Popen(p+['check'],stdout=s.PIPE).stdout.read().decode().split()if n[-1]==',']"
Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away