linux – How do I update a Python package?

linux – How do I update a Python package?

The best way Ive found is to run this command from terminal

sudo pip install [package_name] --upgrade

sudo will ask to enter your root password to confirm the action.


Note: Some users may have pip3 installed instead. In that case, use

sudo pip3 install [package_name] --upgrade

You might want to look into a Python package manager like pip. If you dont want to use a Python package manager, you should be able to download M2Crypto and build/compile/install over the old installation.

linux – How do I update a Python package?

To automatically upgrade all the outdated packages (that were installed using pip), just run the script bellow,

pip install $(pip list --outdated | awk { print $1 }) --upgrade

Here, pip list --outdated will list all the out dated packages and then we pipe it to awk, so it will print only the names.
Then, the $(...) will make it a variable and then, everything is done auto matically. Make sure you have the permissions. (Just put sudo before pip if youre confused)
I would write a script named, pip-upgrade
The code is bellow,

#!/bin/bash
sudo pip install $(pip list --outdated | awk { print $1 }) --upgrade

Then use the following lines of script to prepare it:

sudo chmod +x pip-upgrade
sudo cp pip-upgrade /usr/bin/

Then, just hit pip-upgrade and voila!

Leave a Reply

Your email address will not be published. Required fields are marked *