How to update/upgrade a package using pip?

How to update/upgrade a package using pip?

Hey Shielagaa,

To upgrade a package using pip, you can use the following command:

pip install <package_name> --upgrade

Or in short form:

pip install <package_name> -U

Using sudo will prompt for the root password to confirm the action. While common, this approach is generally considered unsafe.

If you don’t have root access (i.e., you’re not the admin), you should consider working within a virtual environment.

Alternatively, you can use the --user flag to install the package only for the current user:

pip install <package_name> --upgrade --user

Hello Shielagaa,

While off-topic, some may want to update pip itself. For upgrading pip, follow these instructions based on your Python version:

Upgrading pip for Python 3.4+:

Use pip3 as follows:

sudo pip3 install pip --upgrade

This will upgrade pip located at: /usr/local/lib/python3.X/dist-packages.

Upgrading pip for Python 2.7:

Use pip as follows:

sudo pip install pip --upgrade

This will upgrade pip located at: /usr/local/lib/python2.7/dist-packages.