I’m the type of developer who obsesses in keeping my dev-environment up-to-date, this includes all dependency packages. I’m an avid user of Homebrew and with the latest core update, and also, with the release of pip2. I ran into the following issue while trying to update my pip packages:
Before I move forward, I previously wrote “How to Keep All Python Packages Updated in Pip”, however, I recently deprecated the guide.
Note: I’m using a Command-Line shortcut (aka “aliases”), I will show you in a bit how to set-it-up in your .bash_profile or .zshrc.
The following command is the most elegant and straight forward one I’ve seen:
pip freeze --local | grep -v '^\-e' | cut -d = -f 1 | xargs pip install -U
With the latest pip2 update, let’s make two changes:
pip2 freeze --local | grep -v '^\-e' | cut -d = -f 1 | xargs pip2 install -U
There you have it, this command will keep all your packages up-to-date in your virtualenv.
Now, let’s setup the above command as an “alias” that way you don’t have to type it out or be dependent on your bash or zsh history.
There are two ways to accomplish this:
One – Command-Line:
alias pipup='pip2 freeze --local | grep -v '^\-e' | cut -d = -f 1 | xargs pip2 install -U'
Two – Opening either your .bash_profile or .zshrc file:
# pip
alias pipup='pip2 freeze --local | grep -v '^\-e' | cut -d = -f 1 | xargs pip2 install -U'
I personally like to use the second option since I have a lot of aliases and I like to comment which one is which!
I hope you found this tip useful, and if you have any bash or zsh tricks of your own, I’d love to hear about them.