是否可以使用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
之后应该确保没有中断依赖关系。
其他回答
pip install --upgrade `pip list --format=freeze | cut -d '=' -f 1`
pip-list--format=freeze包括pip和setuptools。pip冻结不会。
这应该更有效:
pip3 list -o | grep -v -i warning | cut -f1 -d' ' | tr " " "\n" | awk '{if(NR>=3)print}' | cut -d' ' -f1 | xargs -n1 pip3 install -U
pip-list-o列出过时的包;grep-v-i warning反向匹配警告以避免更新时出错cut-f1-d1''返回第一个单词-过时包的名称;tr“\n|\r”“”将剪切的多行结果转换为单行、空格分隔的列表;awk“{if(NR>=3)print}”跳过标题行cut-d“”-f1获取第一列xargs-n1 pip install-U从管道左侧获取1个参数,并将其传递给命令以升级包列表。
在蝙蝠脚本中
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
使用pipupgrade。。。最新版本2019
$ pip install pipupgrade
$ pipupgrade --verbose --latest --yes
pipupgrade帮助您从requirements.txt文件升级系统、本地或软件包!它还选择性地升级不破坏更改的包。
pipupgrade还确保升级多个Python环境中的包。它与Python2.7+、Python23.4+和pip9+、pip10+、pip18+、pip19+兼容。
注:我是该工具的作者。
Use:
pip install -r <(pip freeze) --upgrade