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.
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
Sample output:
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:
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:
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:
pip cannot find that version, so it prints an error listing every version it knows about:
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:
For a clean list of all 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:
The --dry-run flag (pip 22.2+) simulates the install without actually changing anything.
Comparison of Methods
| Method | Min pip version | Works in scripts | Shows all versions | Needs network |
pip index versions | 21.2 | Yes | Yes | Yes |
pip install ==999.999 | Any | Awkward (parse stderr) | Yes | Yes |
| PyPI JSON API | N/A (uses curl/requests) | Yes | Yes | Yes |
pip install --dry-run | 22.2 | Yes | Only matching | Yes |
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:
To check which versions are compatible with your current Python:
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(orpip.inion Windows) sets a customindex-url, that index is queried instead of public PyPI.
Check your current index configuration:
To query a specific index explicitly:
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:
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
pipfrom a different environment thanpython. Always verify withwhich pipandwhich python(orwhere pipon Windows), or usepython -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 pipto ensure you are querying the right Python environment. - For older pip versions, use
pip install package==999.999as 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
- How to list all available package versions with pip?
- How to list all functions in a module?
- How to list all installed packages and their versions in Python?
- How to list available regions with Boto3 Python
- How to list imported modules?
- How to list Kafka consumer group using python
- How to list only top level directories in Python?
- How to load a model from an HDF5 file in Keras?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack 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.