对3.0 版本的python依赖无法满足_如何在不安装的情况下列出python库的依赖关系?...

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

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

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]

...

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.

EDIT:

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 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.*'

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

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值