Skip to main content

You can use the pip list --outdated command to view a list of installed Python packages that have newer versions available. This command will show you which packages are outdated and can be updated to the latest versions.

Here's how you can use it

pip list --outdated

This command will display a list of installed packages along with their current version and the latest version available. If there is an update available for a package, it will be listed in the output.

To update a specific package, you can use the following command

pip install --upgrade <package_name>

Replace <package_name> with the name of the package you want to update. If you want to update all outdated packages, you can use

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

This command uses pip freeze to list all installed packages, filters out any editable packages (those installed with -e), extracts the package names, and then updates each package to the latest version.

To downgrade a package using pip. You can use the following command

pip install <package_name>==<desired_version>

Replace <package_name> with the name of the package you want to downgrade, and <desired_version> with the version number to which you want to downgrade.

pip install requests==2.25.0

This command will install version 2.25.0 of the requests package. Keep in mind that downgrading a package may lead to compatibility issues with other packages that depend on the newer version, so it's essential to be cautious when downgrading.

If you want to check the available versions of a package, you can use

pip show -v <package_name>

This command will display information about the package, including the available versions. Once you know the version you want, you can use the pip install command to downgrade to that specific version.

 

Downgrade a package

To downgrade a package using pip. You can use the following command

pip install <package_name>==<desired_version>

Replace <package_name> with the name of the package you want to downgrade, and <desired_version> with the version number to which you want to downgrade.

pip install requests==2.25.0

This command will install version 2.25.0 of the requests package. Keep in mind that downgrading a package may lead to compatibility issues with other packages that depend on the newer version, so it's essential to be cautious when downgrading.

If you want to check the available versions of a package, you can use

pip show -v <package_name>

This command will display information about the package, including the available versions. Once you know the version you want, you can use the pip install command to downgrade to that specific version.

 

Upgrade all packages

You can update all installed packages to their latest versions.  Keep in mind that updating packages might introduce compatibility issues, so it's a good practice to check the release notes and test your code after performing updates.

Updating all packages by using the following command

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

This command does the following:

pip freeze --local: Lists all installed packages in your virtual environment
grep -v '^\-e': Filters out any editable packages (those installed with -e)
cut -d = -f 1: Extracts the package names from the list
xargs -n1 pip install -U: Iterates over each package name and upgrades it to the latest version

 

Related articles

Andrew Fletcher20 May 2024
Create a copy of files that go to the tmp directory
To review the content of files being generated in the /tmp directory on an Ubuntu server before Microsoft Defender removes them, you can use several approaches. &nbsp;Following is the approach we took.&nbsp;Real-Time MonitoringYou can set up a script to monitor the /tmp directory and log the...
Andrew Fletcher06 May 2024
Exploring historical memory usage monitoring with Sysstat
In the realm of system administration and monitoring, understanding memory usage trends is crucial for maintaining system health and performance. While tools like htop offer real-time insights into memory usage, they lack the capability to provide historical data. So, what if you need to analyze...