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!
Answer from rbp on Stack OverflowThere 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.
How to UPdate all Python-packages (pip) in one sweep?
how do you upgrade all outdated pip packages?
python - How to update/upgrade a package using pip? - Stack Overflow
Should I just update all pip packages?
Videos
With pip there isn't a concept of 'newest stable' as there is in Debian/Ubuntu.
The 'newest stable' packages in Debian/Ubuntu are tested to work correctly with all the other packages in the distribution.
With pip, you can upgrade all the python modules, but you will upgrade all the modules to the latest version available in the repository. It will be your responsibility to verify that everything still continues to work. There may be issues due to new bugs or incompatible changes.
Because of that never upgrade the OS provided python modules with pip (option: --system) unless you're ready to repair the possible breakage.
It can make a lot of sense to upgrade all the modules installed in your user environment, or better inside a virtual environment. The command should be:
pip freeze | awk '{print $1}' | xargs pip install -U
For users of different distributions and other cases, check:
pip help install
since the default behavior (no --user or --system options) changes from Debian derivatives to standard python.
I've tested this on pip2 and pip3 with success although I'm not sure if there's a better way to do it.
pip freeze | sed 's/==.*//' | xargs pip install -U
You may like to add --user after pip freeze and pip install if you only want to upgrade packages installed to your user account instead of the system. If you're upgrading system Python packages you'll need to run the pip install with sudo otherwise you'll likely hit a permission denied error.
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.
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
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