- List Outdated Packages
- Update All Python Packages
- Update Specific Packages On Windows Or Linux
- References
pip list --outdated
pip freeze | %{$.split('==')[0]} | %{pip install --upgrade $}
To upgrade all packages using pip with grep on Ubuntu Linux
pip3 list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip3 install -U
To upgrade all packages using pip with awk on Ubuntu Linux
pip3 list -o | cut -f1 -d' ' | tr " " "\n" | awk '{if(NR>=3)print}' | cut -d' ' -f1 | xargs -n1 pip3 install -U
-
Freeze packages
pip freeze > requirements.txt
-
Edit
requirements.txt
(set the versions you need for your project) -
Upgrade to the newer/older versions you've setted
pip install -r requirements.txt --upgrade
https://www.activestate.com/resources/quick-reads/how-to-update-all-python-packages/
For Linux it's a lot easier and simpler to use
pip install --upgrade $(pip freeze | sed 's/==.*//g')
To explain what it does, we use a subshell command via
$()
to generate a freeze format output, such asand pipe it with
sed 's/==.*//g'
command to remove the double equals numeric versionand go through all packages in sequential order to check for possible upgrade.
If there is an update, it will proceed to upgrade it, else it will report back a message like