Skip to content

Instantly share code, notes, and snippets.

@haleemur
Last active August 29, 2015 14:23
Show Gist options
  • Save haleemur/5a2db41b888133ee7ba8 to your computer and use it in GitHub Desktop.
Save haleemur/5a2db41b888133ee7ba8 to your computer and use it in GitHub Desktop.
upgrading all installed python files via pip
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
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment