This is the way
Copypip install <package_name> --upgrade
or in short
Copypip 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.
Copypip install <package_name> --upgrade --user
Answer from borgr on Stack OverflowThis is the way
Copypip install <package_name> --upgrade
or in short
Copypip 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.
Copypip install <package_name> --upgrade --user
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:
Copy$ pip install pip-review
Then run:
Copy$ 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
I ran the following command and it upgraded from 1.2.3 to 1.4.0
Copypip install Django --upgrade
Shortcut for upgrade:
Copypip install Django -U
Note: if the package you are upgrading has any requirements this command will additionally upgrade all the requirements to the latest versions available. In recent versions of pip, you can prevent this behavior by specifying --upgrade-strategy only-if-needed. With that flag, dependencies will not be upgraded unless the installed versions of the dependent packages no longer satisfy the requirements of the upgraded package.
According to pip documentation example 3:
Copypip install --upgrade django
But based on my experience, using this method will also upgrade any package related to it. Example:
Assume you want to upgrade somepackage that require Django >= 1.2.4 using this kind of method it will also upgrade somepackage and django to the newest update. Just to be safe, do:
Copy# Assume you want to keep Django 1.2.4
pip install --upgrade somepackage django==1.2.4
Doing this will upgrade somepackage and keeping Django to the 1.2.4 version.
How to upgrade all Python packages with pip - Stack Overflow
how do you upgrade all outdated pip packages?
How to undo or reverse a "pip install -e ." (aka --editable)?
PIP Upgrade not working
Videos
There isn't a built-in flag yet. Starting with pip version 22.3, the --outdated and --format=freeze have become mutually exclusive. Use Python, to parse the JSON output:
Copypip --disable-pip-version-check list --outdated --format=json | python -c "import json, sys; print('\n'.join([x['name'] for x in json.load(sys.stdin)]))" | xargs -n1 pip install -U
If you are using pip<22.3 you can use:
Copypip list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip install -U
For older versions of pip:
Copypip freeze --local | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip install -U
The
grepis to skip editable ("-e") package definitions, as suggested by @jawache. (Yes, you could replacegrep+cutwithsedorawkorperlor...).The
-n1flag forxargsprevents stopping everything if updating one package fails (thanks @andsens).
Note: there are infinite potential variations for this. I'm trying to keep this answer short and simple, but please do suggest variations in the comments!
To upgrade all local packages, you can install pip-review:
Copy$ pip install pip-review
After that, you can either upgrade the packages interactively:
Copy$ pip-review --local --interactive
Or automatically:
Copy$ pip-review --local --auto
pip-review is a fork of pip-tools. See pip-tools issue mentioned by @knedlsepp. pip-review package works but pip-tools package no longer works. pip-review is looking for a new maintainer.
pip-review works on Windows since version 0.5.
pip freeze -o > requirements.txt
output:
Usage: pip freeze [options] no such option: -o
i want to convert all the outdated pip packages to a requirements format and contain it into requirements.txt.