如何使用 pip 升级所有 Python 包 [英] How to upgrade all Python packages with pip

查看:53
本文介绍了如何使用 pip 升级所有 Python 包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用 pip?

注意:功能请求这在官方问题跟踪器上.

Note: that there is a feature request for this on the official issue tracker.

推荐答案

以下内容适用于 Windows,也适用于其他人($ 是您所在的任何目录,在命令提示符下. 例如,C:/Users/Username).

The following works on Windows and should be good for others too ($ is whatever directory you're in, in the command prompt. For example, C:/Users/Username).

$ pip freeze > requirements.txt

打开文本文件,将 == 替换为 >=,或者让 sed 为你做:

Open the text file, replace the == with >=, or have sed do it for you:

$ sed -i 's/==/>=/g' requirements.txt

并执行:

$ pip install -r requirements.txt --upgrade

如果您遇到某个包延迟升级的问题(有时NumPy),只需转到目录 ($),注释掉名称(在它之前添加 #)并再次运行升级.您可以稍后取消对该部分的注释.这也非常适合复制 Python 全局环境.

If you have a problem with a certain package stalling the upgrade (NumPy sometimes), just go to the directory ($), comment out the name (add a # before it) and run the upgrade again. You can later uncomment that section back. This is also great for copying Python global environments.

另一种方式:

我也喜欢 pip-review 方法:

I also like the pip-review method:

py2
$ pip install pip-review

$ pip-review --local --interactive

py3
$ pip3 install pip-review

$ py -3 -m pip_review --local --interactive

您可以选择a"升级所有软件包;如果一次升级失败,请再次运行,并在下一次继续.

You can select 'a' to upgrade all packages; if one upgrade fails, run it again and it continues at the next one.

这篇关于如何使用 pip 升级所有 Python 包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆