是否可以使用pip一次性升级所有Python包?
注意:官方问题跟踪器上对此有一个功能请求。
是否可以使用pip一次性升级所有Python包?
注意:官方问题跟踪器上对此有一个功能请求。
当前回答
这是Python 3的PowerShell解决方案:
pip3 list --outdated --format=legacy | ForEach { pip3 install -U $_.split(" ")[0] }
对于Python 2:
pip2 list --outdated --format=legacy | ForEach { pip2 install -U $_.split(" ")[0] }
这将逐个升级软件包。因此
pip3 check
pip2 check
之后应该确保没有中断依赖关系。
其他回答
这是Python 3的PowerShell解决方案:
pip3 list --outdated --format=legacy | ForEach { pip3 install -U $_.split(" ")[0] }
对于Python 2:
pip2 list --outdated --format=legacy | ForEach { pip2 install -U $_.split(" ")[0] }
这将逐个升级软件包。因此
pip3 check
pip2 check
之后应该确保没有中断依赖关系。
Use:
import pip
pkgs = [p.key for p in pip.get_installed_distributions()]
for pkg in pkgs:
pip.main(['install', '--upgrade', pkg])
甚至:
import pip
commands = ['install', '--upgrade']
pkgs = commands.extend([p.key for p in pip.get_installed_distributions()])
pip.main(commands)
它的工作速度很快,因为它不会不断发射炮弹。
pip list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip install -U
使用AWK更新包:
pip install -U $(pip freeze | awk -F'[=]' '{print $1}')
Windows PowerShell更新
foreach($p in $(pip freeze)){ pip install -U $p.Split("=")[0]}
cmd中的一行:
for /F "delims= " %i in ('pip list --outdated --format=legacy') do pip install -U %i
因此
管道检查
之后应该确保没有中断依赖关系。