Simple one-line powershell command that upgrades all pip modules.
Most websites online use pip freeze
and pipe it to upgrade all modules, but freeze doesn't include these modules (output of pip list --outdated
):
Package Version Latest Type
---------- ------- ------ -----
pip 21.3.1 22.0.4 wheel
setuptools 58.1.0 62.0.0 wheel
wheel 0.37.0 0.37.1 wheel
And possibly others.
Pipe the result of each line in pip list --outdated
.
pip list --outdated | Select-Object -Skip 2 | ForEach-Object {$_.split(' ')[0]} | ForEach-Object {pip install --upgrade $_}
Same result with short-hand version:
pip list --outdated | select -Skip 2 | % {pip install --upgrade $_.split(' ')[0]}
-
Get the list of outdated pip modules. (Same list produced above)
pip list --outdated
-
List produces a header and line separator. We want to skip those 2 lines. So:
Select-Object -Skip 2
-
Parse the text in each line so that we extract only the names. Using space as a delimiter, we will get the first word in the first element of each array.
ForEach-Object {$_.split(' ')[0]}
-
Pipe the output of the previous step to the command to upgrade said module.
ForEach-Object {pip install --upgrade $_}