如何从PIP要求文件中获取包位置列表?

时间:2016-04-29 02:31:02

标签: python pip

有没有办法从PIP生成列表到文件中的实际资源?例如,如果我有一个带有

的需求文件
Flask
Flask-Login

我希望输出类似于:

Name: Flask
Version: 0.10.1
Summary: A microframework based on Werkzeug, Jinja2 and good intentions
Home-page: http://github.com/mitsuhiko/flask/

Name: Flask-Login
Version: 0.3.2
Summary: User session management for Flask
Home-page: https://github.com/maxcountryman/flask-login

我发现了来自pip show的信息,但希望它能够运行在requirements.txt文件中的所有要求。

1 个答案:

答案 0 :(得分:1)

您可以使用XMLRPC API

在PyPI中查找包
sleep

打印:

try:
    import xmlrpclib  # Python 2
except ImportError:
    import xmlrpc.client as xmlrpclib  # Python 3

pypi = xmlrpclib.ServerProxy('http://pypi.python.org/pypi')

package_name = "Flask-Login"

packages = pypi.search({"name": package_name})
package = next(package for package in packages if package["name"] == package_name)
release_data = pypi.release_data(package_name, package["version"])

print(package_name)
print(package["version"])
print(release_data["summary"])
print(release_data["home_page"])