是否可以使用pip一次性升级所有Python包?
注意:官方问题跟踪器上对此有一个功能请求。
是否可以使用pip一次性升级所有Python包?
注意:官方问题跟踪器上对此有一个功能请求。
当前回答
拉玛纳的回答对我来说是最好的,但我不得不补充几点:
import pip
for dist in pip.get_installed_distributions():
if 'site-packages' in dist.location:
try:
pip.call_subprocess(['pip', 'install', '-U', dist.key])
except Exception, exc:
print exc
站点包检查排除了我的开发包,因为它们不在系统站点包目录中。try-except只是跳过已从PyPI中删除的包。
对于endolith:我也希望有一个简单的pip.install(dist.key,upgrade=True),但它看起来不像是要让命令行以外的任何东西使用pip(文档没有提到内部API,pip开发人员也没有使用docstring)。
其他回答
这是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升级程序
使用该库,您可以轻松升级所有依赖项包这些是您遵循的设置。
pip安装pip升级程序
pip升级路径/of/requirements_txt_file
交互式pip需求升级程序。因为逐包升级需求是件麻烦事。它还会更新requirements.txt文件中的版本。
通过拉取请求发送给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
这里发布的所有解决方案都打破了依赖关系。
在此对话中,将功能直接包含到pip中,包括正确管理依赖关系:
的作者https://github.com/kdeldycke/meta-package-manager写入MPM可以模拟缺少的upgrade all命令:
mpm --pip upgrade --all
你可以试试这个:
for i in ` pip list | awk -F ' ' '{print $1}'`; do pip install --upgrade $i; done