How to update / update a package using pip?

How to update a package using pip? those do not work:

pip update
pip upgrade

I know this is a simple question, but it is necessary because it is not so easy to find (pip documentation does not appear, and other questions are relevant because of, but not quite about that)

+96
source share
4 answers

Way

sudo pip install [package_name] --upgrade

or shorter

sudo pip install [package_name] -U

sudo asks you to enter the root password to confirm the action.

If you do not have a root password (unless you are an administrator), you should probably work with virtualenv, and then you should remove sudo:

pip install [package_name] --upgrade
+167
source

The tl; dr script to update all installed packages

, @borgr answer. , , , . pip , sh . pip list, awk ( cut tail) . :

for i in $(pip list -o | awk 'NR > 2 {print $1}'); do sudo pip install -U $i; done

root. , --user pip virtualenv.

+7
import subprocess as sbp
import pip
pkgs = eval(str(sbp.run("pip3 list -o --format=json", shell=True,
                         stdout=sbp.PIPE).stdout, encoding='utf-8'))
for pkg in pkgs:
    sbp.run("pip3 install --upgrade " + pkg['name'], shell=True)

xx.py
Python3 xx.py
: python3. 5+ pip10. 0+

+4

For a non-specific package and a more general solution, you can use pip-review , a tool that checks which packages can / should be updated.

$ 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
+2
source

Source: https://habr.com/ru/post/1688578/


All Articles