Python
Pip
Programming
Software Development
Package Management

How to list all available versions of a package with pip

Codemia Knowledge Hub ·

Run pip index versions <package> to list all available versions of a Python package. It queries the configured package index (usually PyPI) and prints every published version, which is the fastest way to see what exists before pinning, downgrading or upgrading a dependency.

pip index versions

bash
pip index versions requests

Sample output:

 
requests (2.32.3)
Available versions: 2.32.3, 2.32.2, 2.32.1, 2.32.0, 2.31.0, 2.30.0, ...

The first line is the latest version; the second lists all published versions in descending order. Install the one you need explicitly:

bash
pip install requests==2.31.0

Use python -m pip to pick the interpreter

With several Python installations, bare pip may belong to a different interpreter than you expect. python -m pip ties the command to a specific Python:

bash
python -m pip index versions numpy
python3.11 -m pip index versions numpy

This avoids the classic "I installed the package but Python cannot find it" problem, which almost always means pip and python pointed to different interpreters.

Alternatives for older pip

pip index versions was introduced in pip 21.2 (July 2021). On older pip, or when you need more detail, use one of these.

The nonexistent-version trick

Ask for a version that does not exist:

bash
pip install requests==999.999

pip cannot find it, so the error lists every version it knows about:

 
ERROR: Could not find a version that satisfies the requirement requests==999.999
(from versions: 0.2.0, 0.2.1, 0.2.2, ..., 2.32.3)

It works on any pip version but is a hack; prefer pip index versions when available.

The PyPI JSON API

PyPI exposes a JSON endpoint for every package, which suits scripts and CI pipelines:

bash
curl -s https://pypi.org/pypi/requests/json | python -m json.tool | grep '"version"'

For a clean list of all versions:

python
1import requests
2
3url = "https://pypi.org/pypi/requests/json"
4data = requests.get(url).json()
5versions = list(data["releases"].keys())
6print("\n".join(versions))

Because it queries PyPI directly, it always shows the public index regardless of local pip configuration.

Versions matching a constraint

bash
1# Include pre-release and development versions
2pip index versions requests --pre
3
4# Or use pip install to check compatibility
5pip install 'requests>=2.28,<2.31' --dry-run

--dry-run (pip 22.2+) simulates the install without changing anything.

Comparing the methods

MethodMin pip versionWorks in scriptsShows all versionsNeeds network
pip index versions21.2YesYesYes
pip install ==999.999AnyAwkward (parse stderr)YesYes
PyPI JSON APIN/A (uses curl/requests)YesYesYes
pip install --dry-run22.2YesOnly matchingYes

Listed but not installable on your Python

Packages declare supported Python versions in their metadata, and pip enforces them at install time. A listed version can still fail with:

 
ERROR: Package requires a different Python: 3.8.10 not in '>=3.9'

To see which versions fit a given Python:

bash
pip index versions numpy --python-version 3.9

If your pip lacks that flag, check the package's PyPI page: the "Programming Language" classifiers and Requires-Python metadata say exactly which interpreters are supported.

Private indexes and mirrors

pip index versions queries whatever index pip is configured to use:

  • On a corporate network with a private PyPI mirror, you see only what the mirror has synced.
  • If pip.conf (or pip.ini on Windows) sets a custom index-url, that index is queried instead of public PyPI.

Check the current index:

bash
pip config get global.index-url

Query a specific index explicitly:

bash
pip index versions requests --index-url https://pypi.org/simple/

This is the quickest way to debug "why is version X missing?", which often turns out to be a mirror that has not synced yet.

Upgrading pip when index versions is missing

"No such command" means your pip is older than 21.2:

bash
1# Check current pip version
2pip --version
3
4# Upgrade pip
5python -m pip install --upgrade pip
6
7# Verify
8pip --version

Where upgrading pip is not an option (locked-down CI images, system Python), use the ==999.999 trick or the PyPI JSON API.

Things that cause confusion

  • Wrong environment. pip and python from different environments is the most common source of confusion. Verify with which pip and which python (where pip on Windows), or use python -m pip.
  • Available is not installable. The listing shows what is published, not what fits your Python version, OS or architecture.
  • Private index lag. Corporate mirrors may be hours or days behind PyPI. Check the public index before assuming a new release does not exist.
  • Not pinning afterward. Pin the chosen version in requirements.txt, pyproject.toml or a lock file so every team member and CI run uses the same one.
  • Pre-releases are hidden. pip hides alpha, beta and rc versions unless you pass --pre.

Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Basis Lab
No course covers this one yet

Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.

Build my course
Data Structures & Algorithms practice on Codemia

Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.

Practice algorithms