如何使用pip升级所有Python软件包? [英] How to upgrade all Python packages with pip?
问题描述
是否可以使用 pip
一次升级所有Python软件包. ?
注意:存在功能请求可以在官方问题跟踪器上查看.
Note: that there is a feature request for this on the official issue tracker.
推荐答案
尚无内置标志,但您可以使用
There isn't a built-in flag yet, but you can use
pip list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip install -U
注意:为此存在无限的潜在变化.我试图使这个答案简短而简单,但请在评论中提出一些建议!
Note: there are infinite potential variations for this. I'm trying to keep this answer short and simple, but please do suggest variations in the comments!
在pip
的旧版本中,您可以改用此:
In older version of pip
, you can use this instead:
pip freeze --local | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip install -U
grep
将跳过@jawache建议的可编辑("-e")软件包定义. (是的,您可以将grep
+ cut
替换为sed
或awk
或perl
或...).
The grep
is to skip editable ("-e") package definitions, as suggested by @jawache. (Yes, you could replace grep
+cut
with sed
or awk
or perl
or...).
xargs
的-n1
标志可防止在更新一个软件包失败时停止所有操作(感谢 @andsens ).
The -n1
flag for xargs
prevents stopping everything if updating one package fails (thanks @andsens).
这篇关于如何使用pip升级所有Python软件包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!