sudo pip3 freeze | awk -F "==" '{print $1}' | xargs sudo pip3 install --upgrade
I've struggled with this before. So, I'm writing it down for future reference.
AFAIK, pip doesn't support upgrading packages en-masse. But with shell piping, we can achieve the equivalent of
pip install --upgrade ALL.
And, its usually the 2nd part of the pipe that I get stuck on, because I'm not very AWKward (hehe, bad pun for myself).
# treats the input as a file
awk -F
# splits the file columns on this as delimiter
"=="
# prints the first column
{print $1}
Its so handy that awk will let one think of any \n
separated input as a file. This makes column extraction easy, avoids writing a loop, and generally imposes a way of thinking that results in fewer lines of typed shell commands.
:)
NOTE: Sometimes, I want to upgrade all packages, except a few, which I know to be forwards-incompatible with my codebase.
I can do two things:
-
To suppress one package
sudo pip3 freeze | awk -F "==" '{print $1}' | grep -v suppressed-package | xargs sudo pip3 install --upgrade
-
To suppress a bunch of packages
# TODO