是否可以使用pip一次性升级所有Python包?
注意:官方问题跟踪器上对此有一个功能请求。
是否可以使用pip一次性升级所有Python包?
注意:官方问题跟踪器上对此有一个功能请求。
当前回答
我试过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)
其他回答
我在pip问题讨论中找到的最简单、最快的解决方案是:
pip install pipdate
pipdate
资料来源:https://github.com/pypa/pip/issues/3819
从…起https://github.com/cakebread/yolk:
$ pip install -U `yolk -U | awk '{print $1}' | uniq`
然而,你需要先得到蛋黄:
$ sudo pip install -U yolk
拉玛纳的回答对我来说是最好的,但我不得不补充几点:
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)。
在蝙蝠脚本中
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
在查阅Rob van der Woude的for优秀文档后,Windows版本:
for /F "delims===" %i in ('pip freeze') do pip install --upgrade %i