Python
Pip
Programming
Software Development
Package Management

How to list all available package versions with pip?

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

Use pip index versions <package> to list all available versions of a Python package. This command queries the configured package index (usually PyPI) and prints every published version, making it the fastest way to check what is available before pinning, downgrading, or upgrading a dependency.

The Standard Command: 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 shows the latest version. The second line lists all published versions in descending order. Once you identify the version you need, install it explicitly:

bash
pip install requests==2.31.0

Using python -m pip instead of bare pip

When you have multiple Python installations, the bare pip command may point to a different interpreter than you expect. Using 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.

Alternative Methods

The pip index versions subcommand was introduced in pip 21.2 (July 2021). If you are working with an older pip, or you need more detail than the basic listing provides, several alternatives exist.

Method 1: Intentional version mismatch trick

This older workaround forces pip to show all versions by requesting one that does not exist:

bash
pip install requests==999.999

pip cannot find that version, so it prints an error listing 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 it is a hack. Prefer pip index versions when available.

Method 2: Query the PyPI JSON API

PyPI exposes a JSON endpoint for every package. This is useful in scripts or 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))

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

Method 3: Use pip install with a version specifier

You can list versions compatible with specific constraints:

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

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

Comparison of 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

Filtering Versions by Python Compatibility

Not every listed version installs on every Python version. Packages declare their supported Python versions in metadata, and pip respects those constraints during install. A version that appears in the listing may still fail with:

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

To check which versions are compatible with your current Python:

bash
pip index versions numpy --python-version 3.9

If that flag is not available in your pip version, check the package's PyPI page manually. The "Programming Language" classifiers and the Requires-Python metadata field tell you exactly which interpreters are supported.

Working with Private Indexes and Mirrors

pip index versions queries whatever index pip is configured to use. That means:

  • 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 your current index configuration:

bash
pip config get global.index-url

To query a specific index explicitly:

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

This is useful for debugging "why is version X missing?" problems. The answer is often that the private mirror has not synced it yet.

Upgrading pip When index versions Is Missing

If pip index versions returns an error like "No such command," 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

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

Common Pitfalls

  • Wrong Python environment. The most common reason for confusion is running pip from a different environment than python. Always verify with which pip and which python (or where pip on Windows), or use python -m pip.
  • Confusing "available" with "installable." A version appears in the listing but requires a different Python version, OS, or architecture. The listing shows what is published, not what is compatible with your system.
  • Private index lag. Corporate mirrors may be hours or days behind public PyPI. If a newly released version is missing, check the public index directly before assuming it does not exist.
  • Forgetting to pin after checking. Listing versions is reconnaissance. The actual value comes from pinning the chosen version in requirements.txt, pyproject.toml, or a lock file so that every team member and CI run uses the same thing.
  • Pre-release versions hidden by default. pip hides pre-release versions (alpha, beta, rc) unless you pass --pre. If you are looking for a release candidate, add that flag.

Summary

  • pip index versions <package> is the standard way to list all available versions from the configured index.
  • Use python -m pip to ensure you are querying the right Python environment.
  • For older pip versions, use pip install package==999.999 as a fallback to see all versions in the error output.
  • The PyPI JSON API (https://pypi.org/pypi/<package>/json) provides programmatic access for scripts.
  • "Available" means published on the index, not necessarily compatible with your Python version or platform.
  • Always pin the chosen version in a requirements or lock file after selecting it.
  • If a version seems missing, verify your index configuration with pip config get global.index-url.

Related reading
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
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.