是否可以使用pip一次性升级所有Python包?
注意:官方问题跟踪器上对此有一个功能请求。
是否可以使用pip一次性升级所有Python包?
注意:官方问题跟踪器上对此有一个功能请求。
当前回答
JSON+jq答案:
pip list -o --format json | jq '.[] | .name' | xargs pip install -U
其他回答
具有管理员权限的PowerShell 5.1、Python 3.6.5和pip版本10.0.1中的一行:
pip list -o --format json | ConvertFrom-Json | foreach {pip install $_.name -U --no-warn-script-location}
如果列表中没有破损的包裹或特殊的轮子,它会顺利工作。。。
我试过Ramana的代码,我发现在Ubuntu上,每个命令都必须写sudo。这是我在Ubuntu 13.10(Saucy Salamander)上运行良好的脚本:
#!/usr/bin/env python
import pip
from subprocess import call
for dist in pip.get_installed_distributions():
call("sudo pip install --upgrade " + dist.project_name, shell=True)
在蝙蝠脚本中
call pip freeze > requirements.txt
call powershell "(Get-Content requirements.txt) | ForEach-Object { $_ -replace '==', '>=' } | Set-Content requirements.txt"
call pip install -r requirements.txt --upgrade
pip install --upgrade `pip list --format=freeze | cut -d '=' -f 1`
pip-list--format=freeze包括pip和setuptools。pip冻结不会。
改用pipx:
pipx upgrade-all