是否可以使用pip一次性升级所有Python包?
注意:官方问题跟踪器上对此有一个功能请求。
是否可以使用pip一次性升级所有Python包?
注意:官方问题跟踪器上对此有一个功能请求。
当前回答
我在pip问题讨论中找到的最简单、最快的解决方案是:
pip install pipdate
pipdate
资料来源:https://github.com/pypa/pip/issues/3819
其他回答
改用pipx:
pipx upgrade-all
cmd中的一行:
for /F "delims= " %i in ('pip list --outdated --format=legacy') do pip install -U %i
因此
管道检查
之后应该确保没有中断依赖关系。
通过拉取请求发送给pip人员;同时使用我写的这个pip库解决方案:
from pip import get_installed_distributions
from pip.commands import install
install_cmd = install.InstallCommand()
options, args = install_cmd.parse_args([package.project_name
for package in
get_installed_distributions()])
options.upgrade = True
install_cmd.run(options, args) # Chuck this in a try/except and print as wanted
具有管理员权限的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}
如果列表中没有破损的包裹或特殊的轮子,它会顺利工作。。。
如果您安装了pip<22.3,则使用纯Bash/Z外壳一个衬垫实现:
for p in $(pip list -o --format freeze); do pip install -U ${p%%=*}; done
或者,以一种格式良好的方式:
for p in $(pip list -o --format freeze)
do
pip install -U ${p%%=*}
done
在这之后,您将得到pip>=22.3,其中-o和--format冻结是互斥的,您不能再使用这一行。