pip --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)]))"
from pip import get_installed_distributionsfrom pip.commands import install
install_cmd = install.InstallCommand()
options, args = install_cmd.parse_args([package.project_namefor package inget_installed_distributions()])
options.upgrade = Trueinstall_cmd.run(options, args) # Chuck this in a try/except and print as wanted
pip list --format freeze --outdated | sed 's/=.*//g' | sed 's/^<First characters of the first error>.*//' | sed 's/^<First characters of the second error>.*//' | xargs pip install -U
import pip, tempfile, contextlib
with tempfile.TemporaryFile('w+') as temp:with contextlib.redirect_stdout(temp):pip.main(['list', '-o'])temp.seek(0)for line in temp:pk = line.split()[0]print('--> updating', pk, '<--')pip.main(['install', '-U', pk])
# Match lines from pip's local package list output# that meet the following three criteria and pass the# package name to the replacement string in group 1.# (a) Do not start with invalid characters# (b) Follow the rule of no white space in the package names# (c) Immediately follow the package name with an equal signsed="s/^([^=# \t\\][^ \t=]*)=.*"
# Separate the output of package upgrades with a blank linesed="$sed/echo"
# Indicate what package is being processedsed="$sed; echo Processing \1 ..."
# Perform the upgrade using just the valid package namesed="$sed; pip3 install -U \1"
# Output the commandssed="$sed/p"
# Stream edit the list as above# and pass the commands to a shellpip3 freeze --local | sed -rn "$sed" | sh
usage: pip_upgrade_outdated [-h] [-3 | -2 | --pip_cmd PIP_CMD][--serial | --parallel] [--dry_run] [--verbose][--version]
Upgrade outdated python packages with pip.
optional arguments:-h, --help show this help message and exit-3 use pip3-2 use pip2--pip_cmd PIP_CMD use PIP_CMD (default pip)--serial, -s upgrade in serial (default)--parallel, -p upgrade in parallel--dry_run, -n get list, but don't upgrade--verbose, -v may be specified multiple times--version show program's version number and exit
@echo offSetlocal EnableDelayedExpansionrem https://stackoverflow.com/questions/2720014/
echo Upgrading pip...python -m pip install --upgrade pipecho.
echo Upgrading packages...set upgrade_count=0pip list --outdated > pip-upgrade-outdated.txtfor /F "skip=2 tokens=1,3 delims= " %%i in (pip-upgrade-outdated.txt) do (echo ^>%%iset package=%%iset latest=%%jset requirements=!package!
rem for each outdated package check for any version requirements:set dotest=1for /F %%r in (.\python\requirements.txt) do (if !dotest!==1 (call :substr "%%r" !package! _substrrem check if a given line refers to a package we are about to upgrade:if "%%r" NEQ !_substr! (rem check if the line contains more than just a package name:if "%%r" NEQ "!package!" (rem set requirements to the contents of the line:echo requirements: %%r, latest: !latest!set requirements=%%r)rem stop testing after the first instance found,rem prevents from mistakenly matching "py" with "pylint", "numpy" etc.rem requirements.txt must be structured with shorter names going firstset dotest=0)))rem pip install !requirements!pip install --upgrade !requirements!set /a "upgrade_count+=1"echo.)
if !upgrade_count!==0 (echo All packages are up to date.) else (type pip-upgrade-outdated.txt)
if "%1" neq "-silent" (echo.set /p temp="> Press Enter to exit...")exit /b
:substrrem string substition done in a separate subroutine -rem allows expand both variables in the substring syntax.rem replaces str_search with an empty string.rem returns the result in the 3rd parameter, passed by reference from the caller.set str_source=%1set str_search=%2set str_result=!str_source:%str_search%=!set "%~3=!str_result!"rem echo !str_source!, !str_search!, !str_result!exit /b
import subprocessimport re
pkg_list = subprocess.getoutput('pip freeze')
pkg_list = pkg_list.split('\n')
new_pkg = []for i in pkg_list:re.findall(r"^(.*)==.*", str(i))new = re.findall(r"^(.*)==.*", str(i))[0]new_pkg.append(new)
for i in new_pkg:print(subprocess.getoutput('pip install '+str(i)+' --upgrade'))