1
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?

More than 5 years have passed since last update.

pip3のパッケージを一括でアップデートするためのシェルスクリプト

Posted at

pip3のパッケージをワンライナーで雑に一括アップデート出来なかったので、シェルスクリプトを書きました。
実行後にpip3 checkで依存関係を確認しましょう。

# !/bin/zsh
# 更新が必要なパッケージの名前をファイルに書き出す
pip3 list -o | awk '{print $1}' > outdated_pip3_packages.txt

# ファイルの中身、3行目からパッケージ名が並んでいる
# Package
# ----------
# numpy
# pandas
# ~~~

# 書き出したファイルを1行ずつ読み込んでアップデート
cnt=0
while read line
do
  cnt=`expr $cnt + 1`
  if test $cnt -ge 3 ; then # パッケージ名が並ぶのは3行目から
    echo "Updating package $line..."
    pip3 install -U $line
  fi
done < outdated_pip3_packages.txt
echo "Update $cnt packages done!"

# パッケージの更新に使ったファイルを消す
rm outdated_pip3_packages.txt
1
0
2

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
1
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?