是否可以使用pip一次性升级所有Python包?
注意:官方问题跟踪器上对此有一个功能请求。
是否可以使用pip一次性升级所有Python包?
注意:官方问题跟踪器上对此有一个功能请求。
当前回答
使用pipupgrade。。。最新版本2019
$ pip install pipupgrade
$ pipupgrade --verbose --latest --yes
pipupgrade帮助您从requirements.txt文件升级系统、本地或软件包!它还选择性地升级不破坏更改的包。
pipupgrade还确保升级多个Python环境中的包。它与Python2.7+、Python23.4+和pip9+、pip10+、pip18+、pip19+兼容。
注:我是该工具的作者。
其他回答
python -c 'import pip; [pip.main(["install", "--upgrade", d.project_name]) for d in pip.get_installed_distributions()]'
一行!
拉玛纳的回答对我来说是最好的,但我不得不补充几点:
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)。
从…起https://github.com/cakebread/yolk:
$ pip install -U `yolk -U | awk '{print $1}' | uniq`
然而,你需要先得到蛋黄:
$ sudo pip install -U yolk
拉玛纳回答的一个线性版本。
python -c 'import pip, subprocess; [subprocess.call("pip install -U " + d.project_name, shell=1) for d in pip.get_installed_distributions()]'
使用pip升级程序
使用该库,您可以轻松升级所有依赖项包这些是您遵循的设置。
pip安装pip升级程序
pip升级路径/of/requirements_txt_file
交互式pip需求升级程序。因为逐包升级需求是件麻烦事。它还会更新requirements.txt文件中的版本。