[PYTHON] Shell script for batch update of pip3 packages

I couldn't update the pip3 package all at once with one liner, so I wrote a shell script. Let's check the dependency with pip3 check after execution.

#!/bin/zsh
#Write the name of the package that needs to be updated to a file
pip3 list -o | awk '{print $1}' > outdated_pip3_packages.txt

#The contents of the file, the package name is lined up from the third line
# Package
# ----------
# numpy
# pandas
# ~~~

#Update by reading the exported file line by line
cnt=0
while read line
do
  cnt=`expr $cnt + 1`
  if test $cnt -ge 3 ; then #Package names are lined up from the 3rd line
    echo "Updating package $line..."
    pip3 install -U $line
  fi
done < outdated_pip3_packages.txt
echo "Update $cnt packages done!"

#Delete the files used to update the package
rm outdated_pip3_packages.txt

Recommended Posts

Shell script for batch update of pip3 packages
Summary of yum packages required for pip install on EC2
Shell script basics # 2
[Recommended tagging for machine learning # 2] Extension of scraping script
[Recommended tagging for machine learning # 2.5] Modification of scraping script
Find out the location of packages installed with pip