Last updated: Apr 9, 2024
Reading timeยท3 min

Use the pip install package== command to list all of the available versions
of a Python package using pip, e.g. pip install requests==.
The output contains a tuple of all of the versions of the package from the oldest to the most recent version.
# ๐๏ธ For pip >=21.1 pip install requests== # ๐๏ธ For pip >=20.3 pip install --use-deprecated=legacy-resolver requests== # ๐๏ธ For pip >=21.2 (experimental - might change) pip index versions requests

The versions of the package will be printed without having to download the actual package.
requests package. Make sure to replace requests with your specific package.You can check your version of pip with the pip --version command.
pip --version pip3 --version

If you have an older version of pip, you can upgrade it with the following command.
# ๐๏ธ If you have pip already installed pip install --upgrade pip # ๐๏ธ If your pip is aliased as pip3 (Python 3) pip3 install --upgrade pip # ๐๏ธ If you don't have pip in your PATH environment variable python -m pip install --upgrade pip # ๐๏ธ If you don't have pip in your PATH environment variable python3 -m pip install --upgrade pip
If you pip version is greater than or equal to 21.1, run the
pip install example== command with two equal signs after the package name.
# ๐๏ธ For pip >=21.1 pip install requests==

You can install a specific version of the package by specifying the version after the two equal signs.
# ๐๏ธ In a virtual environment or using Python 2 pip install requests==2.28.1 # ๐๏ธ For Python 3 pip3 install requests==2.28.1 # ๐๏ธ If you don't have pip in your PATH environment variable python3 -m pip install requests==2.28.1
The example commands install version 2.28.1 of the requests package.
If you already have the package installed, it's best to uninstall it and rerun the command scoped to the specific version.
# ๐๏ธ Uninstall package pip uninstall requests pip3 uninstall requests python3 -m pip uninstall requests # ๐๏ธ Install a specific version of the package pip install requests==2.28.1
If you need to find which version of a specific package is installed, use the
pip show <package-name> command.
pip show requests
If you need to check the versions of all of the installed, packages, use the pip freeze command.
pip freeze
pip version that is in the range 20.3-21.1, you might have to set the --use-deprecated option when checking the versions of the package.# ๐๏ธ For pip >=20.3 <=21.1 pip install --use-deprecated=legacy-resolver requests==
If you use a pip version greater than 21.2, you can also try using the
pip index versions <package-name> command.
# ๐๏ธ For pip >=21.2 (experimental - might change) pip index versions requests

The command returns all of the available versions of the package from the most recent to the oldest.
Alternatively, you can view all versions of a package on its pypi page.
This is a three-step process:
pypi page of the package.
Here is the pypi page for requests.
To pip list all available versions of a package from inside a Python script:
pypi to get the JSON data for the package.releases key.import requests from pkg_resources import parse_version def list_versions(package_name): url = f"https://pypi.org/pypi/{package_name}/json" res = requests.get(url, timeout=5) data = res.json() versions = data['releases'] return sorted(versions, key=parse_version, reverse=True) # ['2.28.1', '2.28.0', '2.27.1', '2.27.0', '2.26.0', '2.25.1', '2.25.0', '2.24.0', ....] print(list_versions('requests'))

The code sample uses the requests package to make an HTTP request, so make
sure to install it if you haven't.
pip install requests pip3 install requests
The list_versions function takes a package name as a parameter and makes an
HTTP request to the pypi JSON API.
We parse the data, access the releases key and sort the versions from most
recent to oldest.