current position:Home>Upgrading Python Packages with Pip

Upgrading Python Packages with Pip

2022-11-08 04:02:54Linux China

Author: Translator:

| 2022-11-07 15:34 Comment:  

When was the last time you updated a Python package installed via Pip?Most users tend to forget that these Python packages also need to be updated manually, because just updating the system repositories won't work for packages.

So, let's take a moment to see how to use Pip to update old Python packages.

How to use Pip to upgrade Python packages

is a command line utilitycommand line utility for managing Python packages.You can use Pip to install Python packages similar to how you manage packages with apt in Ubuntu and Debian.

So, let's take a deep dive into how to use this wonderful tool, Pip, to manage content related to Python packages.

1. List outdated Python packages

Before planning what packages to update, let's first list out what packages are outdated, where you can choose which ones you want to update, since most people don't want to update the entire package repository at once.

To list outdated Python packages, you simply use the pip command with the list option, the --outdated flagYes, as shown below:

pip list --outdated

outdated packages

2. Upgrade specific software packages

Once you have a list of updatable packages, you can select the specific package you want to update as I mentioned earlier. The syntax of the pip upgrade package command is as follows:

pip install package_name -U

For example, I want to upgrade a package named anime-api to the latest version, so I will use the following command to upgrade:

pip install anime-api -U

update anime api

3. Upgrade the package to a specific version

It is not necessary to always use the latest version of the software, if you want to upgrade the package to a specific version that is not the latest, refer to the following command syntax:

pip install --upgrade ==

For example, I want to update a package named xdg to version 5.1, which is the previous version of the latest version, so I can use the following command:

pip install --upgrade xdg==5.1

upgrade xdg to specific iteration

4. Use Pip to upgrade all software at oncePackage

Please note: I do not recommend that you upgrade all packages in one go, because the dependencies of Python packages are too complex for a one-time upgrade to handle interdependencies.

To upgrade all python packages at once, you can use the following command:

pip3 list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip3 install -U

upgrade everything

The above command uses .First, it will get all the packages that need to be updated, and then execute the pip3 install -U command for each package.

I'm using pip3 here, not pip.In Ubuntu 22.04 and later, both the pip and pip3 commands will work.

Summary

Using Pip to update all Python packages at once is not a good idea.I've found dependencies between packages are broken after a one-time update, so make sure you only update the packages you want to update.

If you have any other questions, please leave them in the comments section.


via:

Author: Topic: Translator: Proofreader:

This article is compiled by the original, and launched with honor


copyright notice
author[Linux China],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/312/202211080356011987.html

Random recommended