The Python Oracle

How to update/upgrade a package using pip?

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Music Box Puzzles

--

Chapters
00:00 How To Update/Upgrade A Package Using Pip?
00:23 Accepted Answer Score 1238
00:55 Answer 2 Score 128
01:15 Answer 3 Score 37
01:32 Answer 4 Score 20
01:48 Thank you

--

Full question
https://stackoverflow.com/questions/4707...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #pip

#avk47



ACCEPTED ANSWER

Score 1238


This is the way

pip install <package_name> --upgrade

or in short

pip install <package_name> -U

Using sudo will ask to enter your root password to confirm the action, but although common, is considered unsafe.

If you do not have a root password (if you are not the admin) you should probably work with virtualenv.

You can also use the user flag to install it on this user only.

pip install <package_name> --upgrade --user



ANSWER 2

Score 128


For a non-specific package and a more general solution, you can check out pip-review. A tool that checks what packages could/should be updated.

To install:

$ pip install pip-review

Then run:

$ pip-review --interactive
requests==0.14.0 is available (you have 0.13.2)
Upgrade now? [Y]es, [N]o, [A]ll, [Q]uit y



ANSWER 3

Score 37


Use this code in terminal:

python -m pip install --upgrade PACKAGE_NAME

For example I want update pip package:

python -m pip install --upgrade pip

More examples:

python -m pip install --upgrade selenium
python -m pip install --upgrade requests
...



ANSWER 4

Score 20


I use the following line to update all of my outdated packages:

pip list --outdated --format=freeze | awk -F '==' '{print $1}' | xargs -n1 pip install -U

On newer versions of pip the above breaks, use this instead:

pip list --outdated --format=json | jq '.[].name' | xargs -n1 pip install -U