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