SoFunction
Updated on 2025-04-14

Five ways to view the current installed version and the latest version of a package in Python

Method 1: Use pip and --outdated parameters

You can usepip list --outdatedCommand to see which packages have updated versions available. This command lists all installed packages and their latest versions on PyPI.

pip list --outdated

This outputs a list of packages containing the current and latest versions, for example:

Package    Version   Latest    Type
---------- --------- --------- -----
requests   2.25.1    2.26.0    wheel

Method 2: Use pip search (deprecated in newer versions of pip)

You can usepip searchCommand to search for packages on PyPI. However, this command has been deprecated in newer versions of pip and may not work properly.

pip search requests

This will output relatedrequestsPackage information, including the latest version.

Method 3: Use pip index versions (for pip 21.2 and later)

You can usepip index versionsCommand to display all available versions of a package. The latest version is usually listed at the forefront.

pip index versions requests

This will displayrequestsA list of available versions of the package, the latest version usually appears in the front.

Example of pip index versions

$ pip index versions requests
Available versions for requests:
 - 2.26.0
 - 2.25.1
 - 2.25.0
 - 2.24.0
 - ...

Method 4: Use pypi-simple

pypi-simpleThe package provides a command-line tool for querying PyPI. First, you need to install it:

pip install pypi-simple

Then you can use it to check the latest version of the package:

pypi-simple requests

This outputs the latest version available on PyPI:

requests==2.26.0

Method 5: Use pip in Python scripts

If you prefer to use Python scripts to solve this problem, you can write a small script to get the latest version:

import requests

def get_latest_version(package_name):
    url = f"/pypi/{package_name}/json"
    response = (url)
    if response.status_code == 200:
        data = ()
        return data['info']['version']
    else:
        return None

package_name = "requests"
latest_version = get_latest_version(package_name)
print(f"{package_name} The latest version is {latest_version}.")

You can save this script ascheck_version.pyAnd run it:

python check_version.py

This script will output the latest version of the specified package.

Summarize

This is the introduction to this article about five ways to view the current installation version of a certain package and the latest version of python. For more related python, please search for my previous article or continue browsing the relevant articles below. I hope everyone will support me in the future!