Python and pip, list all versions of a package that's available?
Instantly fetch all versions of a Python package using:
pip install yolk3k && yolk -V <package_name>
This command installs yolk3k (a pretty handy tool), then retrieves the version list for the specified <package_name>
.
Different beats for different pip's versions
Depending on your pip version, different commands are used to display available versions of a package without installing them:
For pip >= 21.2, let's go modern:
pip index versions <package_name> # Feel the rhythm of modern pip
For pip >= 9.0 and <= 21.1, keep it classic:
pip install <package_name>== # Classic always has its charm...
For pip versions around 20.3, vintage style:
pip install --use-deprecated=legacy-resolver <package_name>== # Vintage? No problem
Each command retrieves a list of all available versions for a given package from our dear friend, PyPI.
More than one way to list versions
Listing version information is not restricted to simple command-line usage. Here are some additional tools in the toolbox:
Python's requests to the rescue
Use Python's requests module to get version details from PyPI's JSON API:
-
Fetch from PyPI's JSON API:
-
Sort and display fetched versions data:
Bash scripting with the crew: curl and jq
Use a bash script along with curl and jq to wrangle version data from the pypi.org API:
Don't forget to pass the package name as an argument, and remember that the -L flag is there to redirect URLs. Because we hate dead-ends, don't we?
Verbose mode: When the quiet gets too loud
Sometimes, using verbose mode -v
with pip can help you sneak peak on available versions during installation attempts:
pip install -v <package_name> # Like a backstage pass
This is more like a spy tool rather than a norm. Use it for problem diagnosing.
Watchouts and pointers
While you're busy with Python packages and versions, keep an eye out for these:
Deprecated options and removals
- Be careful with deprecated options or those removed. They're like outdated fashion trends.
- The
--no-install
flag is one of those old-fashioned trends. Instead, put on the--no-deps --no-install
outfit.
Reliability concerns
- Don't trust any stranger scripts that often appear on public forums like pastebin. Treat them like urban myths - fun to talk about but not trustworthy.
Regular updates and code maintenance
- Keep your scripts and methods fresh and updated. Don't let them get dusty and rusty.
More than one way to skin a cat
- Always open to alternative methods, just like that one called Chris's alternative method. Learning never ends.
Was this article helpful?