While using Python as a programming language, it's a very common scenario to use a virtual environment and PIP, a package manager for python.
当使用Python作为编程语言时,使用虚拟环境和PIP (Python的程序包管理器)是一种非常常见的情况。
It's a common practice to use a text file, named as "requirement.txt", which would be populated with the list of libraries used in the given application.
通常,使用文本文件“ requirement.txt” ,其中将填充给定应用程序中使用的库的列表。
Generally, the developers maintain the version of the libraries in the "requirement.txt", as shown in the below example,
通常,开发人员在“ requirement.txt”中维护库的版本,如以下示例所示,
(venv) XXX:src XXX$ more requirements.txt
numpy==1.17.2
requirements.txt (END)
Upgrading every library is a monotonous task, and hence the following commands can be used to upgrade all the packages in the venv (virtual environment) using PIP. We could either follow the below as a two-step process or also combine it to be a single line command.
升级每个库都是一项单调的任务,因此,以下命令可用于使用PIP 升级 venv(虚拟环境)中的所有软件包 。 我们可以按照以下两个步骤进行操作,也可以将其组合为一个单行命令。
Approach 1:
方法1:
Freeze all the libraries to a file called 'requirements.txt' (file name could be anything)
将所有库冻结到一个名为“ requirements.txt”的文件中(文件名可以是任何名称)
pip freeze > installed_library_list.txt
Update all the libraries available in the file
更新文件中所有可用的库
pip install -r installed_library_list.txt –upgrade
Approach 2:
方法二:
pip freeze --local | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip install -U
The grep is to skip editable ("-e") package definitions, and the -n1 flag for xargs prevents stopping everything if updating one package fails.
grep将跳过可编辑的( “ -e” )软件包定义,并且xargs的-n1标志可防止在更新一个软件包失败时停止所有操作。
翻译自: https://www.includehelp.com/python/upgrade-all-python-packages-with-pip.aspx