Python and pip, list all versions of a package tha

2019-01-08 02:57发布

Given the name of a Python (2.X) package that can be installed with pip and virtualenv, is there any way to find out a list of all the possible versions of it that pip could install? Right now it's trial and error.

I'm trying to install a version for a third party library, but the newest version is too new, there were backwards incompatible changes made. So I'd like to somehow have a list of all the versions that pip knows about, so that I can test them.

18条回答
Melony?
2楼-- · 2019-01-08 03:26

You could the yolk3k package instead of yolk. yolk3k is a fork from the original yolk and it supports both python2 and 3.

https://github.com/myint/yolk

pip install yolk3k
查看更多
该账号已被封号
3楼-- · 2019-01-08 03:28

you can grep the result of your pip list

-> % pip list | grep 'beautifulsoup4'

beautifulsoup4 (4.4.1)
查看更多
闹够了就滚
4楼-- · 2019-01-08 03:29

Alternative solution is to use the Warehouse APIs:

https://warehouse.readthedocs.io/api-reference/json/#release

For instance for Flask:

import requests
r = requests.get("https://pypi.org/pypi/Flask/json")
print(r.json()['releases'].keys())

will print:

dict_keys(['0.1', '0.10', '0.10.1', '0.11', '0.11.1', '0.12', '0.12.1', '0.12.2', '0.12.3', '0.12.4', '0.2', '0.3', '0.3.1', '0.4', '0.5', '0.5.1', '0.5.2', '0.6', '0.6.1', '0.7', '0.7.1', '0.7.2', '0.8', '0.8.1', '0.9', '1.0', '1.0.1', '1.0.2'])
查看更多
我命由我不由天
5楼-- · 2019-01-08 03:31

You don't need a third party package to get this information. pypi provides simple JSON feeds for all packages under

https://pypi.python.org/pypi/{PKG_NAME}/json

Here's some Python code using only the standard library which gets all versions.

import json
import urllib2
from distutils.version import StrictVersion

def versions(package_name):
    url = "https://pypi.python.org/pypi/%s/json" % (package_name,)
    data = json.load(urllib2.urlopen(urllib2.Request(url)))
    versions = data["releases"].keys()
    versions.sort(key=StrictVersion)
    return versions

print "\n".join(versions("scikit-image"))

That code prints (as of Feb 23rd, 2015):

0.7.2
0.8.0
0.8.1
0.8.2
0.9.0
0.9.1
0.9.2
0.9.3
0.10.0
0.10.1
查看更多
时光不老,我们不散
6楼-- · 2019-01-08 03:31

You can use this short Python3 snippet to grab the list of available versions for a package from PyPI. Unlike some other Python solutions posted here, this doesn't break on loose versions like django's 1.10rc1 or uwsgi's 2.0.13.1:

>>> import requests
>>> from pkg_resources import parse_version
>>> 
>>> def versions(name):
...     url = "https://pypi.python.org/pypi/{}/json".format(name)
...     return sorted(requests.get(url).json()["releases"], key=parse_version)
... 
>>> print(*reversed(versions("Django")), sep="\n")
1.10.3
1.10.2
1.10.1
1.10
1.10rc1
1.10b1
1.10a1
...
查看更多
男人必须洒脱
7楼-- · 2019-01-08 03:33

For pip >= 9.0 use

$ pip install pylibmc==
Collecting pylibmc==
  Could not find a version that satisfies the requirement pylibmc== (from 
  versions: 0.2, 0.3, 0.4, 0.5.1, 0.5.2, 0.5.3, 0.5.4, 0.5.5, 0.5, 0.6.1, 0.6, 
  0.7.1, 0.7.2, 0.7.3, 0.7.4, 0.7, 0.8.1, 0.8.2, 0.8, 0.9.1, 0.9.2, 0.9, 
  1.0-alpha, 1.0-beta, 1.0, 1.1.1, 1.1, 1.2.0, 1.2.1, 1.2.2, 1.2.3, 1.3.0)
No matching distribution found for pylibmc==

– all the available versions will be printed without actually downloading or installing any additional packages.

For pip < 9.0 use

pip install pylibmc==blork

where blork can be any string that is not likely to be an install candidate.

查看更多
登录 后发表回答