Skip to content

Instantly share code, notes, and snippets.

@SLAPaper
Created February 4, 2019 05:18
Show Gist options
  • Save SLAPaper/ba745b5c8e3c976a85ce14a67972b17a to your computer and use it in GitHub Desktop.
Save SLAPaper/ba745b5c8e3c976a85ce14a67972b17a to your computer and use it in GitHub Desktop.
Pip-Upgrade-All for (Powershell, cmd, bash)
@echo off
for /f "skip=2 tokens=1 delims= " %%a in ('pip list -o') do pip install -U %%a
Param(
[Parameter(Position = 0)]
[string[]]$python_name = ('python'),
[string[]]$Exclude = (''),
[bool]$NoDeps = $false
)
foreach ($python in $python_name) {
Write-Host "Upgrading $($python)'s packages:" -ForegroundColor Cyan
$result = Invoke-Expression "$($python) -m pip list -o"
$start_point = 0
for ($i = 0; $i -lt $result.Length; ++$i) {
$first_column = $result[$i].Split()[0]
if ($first_column -eq "Package") {
$start_point = $i
break
}
}
$filtered_packages_list = @()
for ($i = $start_point + 2; $i -lt $result.Length; ++$i) {
$package_name = $result[$i].Split()[0]
if ($package_name -NotIn $Exclude) {
$filtered_packages_list += $package_name
}
else {
Write-Host "Warning: $($package_name) is outdated but excluded." -ForegroundColor Red
}
}
if ($filtered_packages_list.Length -gt 0) {
Write-Host "Upgrading $($filtered_packages_list -Join ', ')" -ForegroundColor Cyan
$tmpstr = ""
if ($NoDeps) {
$tmpstr = "--no-deps"
}
foreach ($pkg_name in $filtered_packages_list) {
Invoke-Expression "$($python) -m pip install $($tmpstr) --no-warn-script-location --upgrade-strategy eager -U $($tmpstr) $($pkg_name)"
}
}
else {
Write-Host "Nothing to upgrade on $($python)." -ForegroundColor Red
}
Write-Host ""
}
#!/bin/sh
python3 -m pip list -o | tail -n +3 | awk '{print $1}' | xargs -n 1 python3 -m pip install -U
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment