如何在不安装的情况下列出python库的依赖关系? [英] How to list dependencies for a python library without installing?

查看:356
本文介绍了如何在不安装的情况下列出python库的依赖关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种无需先安装即可获取给定python软件包依赖项列表的方法?

Is there a way to get a list of dependencies for a given python package without installing it first?

我目前可以获得要求列表,但是它需要安装软件包.例如,我可以使用pip显示基本需求信息,但其中不包含版本信息:

I can currently get a list of requirements, but it requires installing the packages. For example, I can use pip to show basic requirements info, but it doesn't include version information:

$ pip show pytest
Name: pytest
Version: 3.0.6
...
Requires: colorama, setuptools, py

我尝试了一个名为 pipdeptree 的库,该库包含更好的库输出要求,但还需要安装软件包

I've tried a library called pipdeptree that includes much better output on requirements, but it also requires installation of the packages

$ pipdeptree -p pytest
pytest==3.0.6
- colorama [required: Any, installed: 0.3.7]
- py [required: >=1.4.29, installed: 1.4.32]
- setuptools [required: Any, installed: 34.0.0]
  - appdirs [required: >=1.4.0, installed: 1.4.0]
...

理想情况下,我将获得pipdeptree提供的详细程度.同样,能够从python wheel或pypi与pip生成requirements.txt文件也足够.

Ideally, I would get the level of detail that pipdeptree provides. Also, being able to produce a requirements.txt file from a python wheel or from pypi with pip would suffice as well.

我查看了相似问题.它们要么已经过时,需要安装,要么没有列出给定软件包的单个依赖关系,仅列出了解决依赖关系要求后最终下载的软件包的列表.例如,我不太在乎pip下载package-2.3.4,而是希望package>=2.1是必需的.

I've looked at similar questions. They are either outdated, require installation, or they don't list individual dependencies for a given package, only a list of the final downloaded packages after resolving the dependency requirements. For example, I don't really care that pip downloaded package-2.3.4, I would rather know that package>=2.1 was a requirement.

推荐答案

PyPi为JSON端点提供了包元数据:

PyPi provides a JSON endpoint with package metadata:

>>> import requests
>>> url = 'https://pypi.org/pypi/{}/json'
>>> json = requests.get(url.format('pandas')).json()
>>> json['info']['requires_dist']
['numpy (>=1.9.0)', 'pytz (>=2011k)', 'python-dateutil (>=2.5.0)']
>>> json['info']['requires_python']
'>=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*'

对于特定的软件包版本,请在URL上添加一个附加的版本段:

For a specific package version, add an additional version segment to the URL:

https://pypi.org/pypi/pandas/0.22.0/json

这篇关于如何在不安装的情况下列出python库的依赖关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆