Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
358 views
in Technique[技术] by (71.8m points)

python - 如何使用pip升级所有Python软件包?(How to upgrade all Python packages with pip?)

Is it possible to upgrade all Python packages at one time with pip ?

(是否可以通过pip一次升级所有Python软件包?)

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

(注意 :官方问题追踪器上对此功能有要求 。)

  ask by thedjpetersen translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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!

(我试图使这个答案简短而简单,但是请在评论中提出一些建议!)

In older version of pip , you can use this instead:

(在旧版本的pip ,您可以改用以下命令:)

pip freeze --local | grep -v '^-e' | cut -d = -f 1  | xargs -n1 pip install -U

The grep is to skip editable ("-e") package definitions, as suggested by @jawache.

(grep将跳过@jawache建议的可编辑(“ -e”)软件包定义。)

(Yes, you could replace grep + cut with sed or awk or perl or...).

((是的,您可以将grep + cut替换为sedawkperl或...)。)

The -n1 flag for xargs prevents stopping everything if updating one package fails (thanks @andsens ).

(如果更新一个软件包失败(感谢@andsens ),则xargs-n1标志可阻止停止所有操作。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...