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