如何查找Python包的依赖项 [英] How to find a Python package's dependencies

查看:880
本文介绍了如何查找Python包的依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以编程方式获取Python软件包的依赖关系列表?

How can you programmatically get a Python package's list of dependencies?

标准setup.py已记录了这些内容,但我找不到从Python或命令行从 访问它的简便方法.

The standard setup.py has these documented, but I can't find an easy way to access it from either Python or the command line.

理想情况下,我正在寻找类似的东西:

Ideally, I'm looking for something like:

$ pip install somepackage --only-list-deps
kombu>=3.0.8
billiard>=3.3.0.13
boto>=2.26

或:

>>> import package_deps
>>> package = package_deps.find('somepackage')
>>> print package.dependencies
['kombu>=3.0.8', 'billiard>=3.3.0.13', 'boto>=2.26']

注意,我不是在谈论导入软件包和查找所有引用的模块.尽管这可能找到大多数相关软件包,但无法找到所需的最低版本号.那只存储在setup.py中.

Note, I'm not talking about importing a package and finding all referenced modules. While this might find most of the dependent packages, it wouldn't be able to find the minimum version number required. That's only stored in the setup.py.

推荐答案

除了pip show [package name]命令之外,还有pipdeptree.

In addition to the pip show [package name] command, there is pipdeptree.

就做

$ pip install pipdeptree

然后运行

$ pipdeptree

,它将以树形式显示您的依赖关系,例如

and it will show you your dependencies in a tree form, e.g.,

flake8==2.5.0
  - mccabe [required: >=0.2.1,<0.4, installed: 0.3.1]
  - pep8 [required: !=1.6.0,>=1.5.7,!=1.6.1,!=1.6.2, installed: 1.5.7]
  - pyflakes [required: >=0.8.1,<1.1, installed: 1.0.0]
ipdb==0.8
  - ipython [required: >=0.10, installed: 1.1.0]

该项目位于 https://github.com/naiquevin/pipdeptree ,您将在其中还可以找到使用情况信息.

The project is located at https://github.com/naiquevin/pipdeptree, where you will also find usage information.

这篇关于如何查找Python包的依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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