如何查找 Python 包的依赖项 [英] How to find a Python package's dependencies
问题描述
如何以编程方式获取 Python 包的依赖项列表?
标准的setup.py
有这些文档,但我找不到一种简单的方法来从 Python 或命令行访问它.
理想情况下,我正在寻找类似的东西:
$ pip install somepackage --only-list-deps昆布>=3.0.8台球>=3.3.0.13博托>=2.26
或:
<预><代码>>>>导入 package_deps>>>package = package_deps.find('somepackage')>>>打印 package.dependencies['kombu>=3.0.8','台球>=3.3.0.13','boto>=2.26']注意,我不是在谈论导入包并找到所有引用的模块.虽然这可能会找到大多数依赖包,但它无法找到所需的最低版本号.这仅存储在 setup.py 中.
除了pip show [package name]
命令,还有pipdeptree
.
就去做
$ pip install pipdeptree
然后运行
$ pipdeptree
它会以树的形式向您显示您的依赖项,例如,
flake8==2.5.0- mccabe [要求:>=0.2.1,<0.4,已安装:0.3.1]- pep8 [需要:!=1.6.0,>=1.5.7,!=1.6.1,!=1.6.2, 已安装:1.5.7]- pyflakes [需要:>=0.8.1,<1.1,已安装:1.0.0]ipdb==0.8- ipython [需要:>=0.10,已安装:1.1.0]
该项目位于 https://github.com/naiquevin/pipdeptree,您将在那里还可以找到使用信息.
How can you programmatically get a Python package's list of dependencies?
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
or:
>>> import package_deps
>>> package = package_deps.find('somepackage')
>>> print package.dependencies
['kombu>=3.0.8', 'billiard>=3.3.0.13', 'boto>=2.26']
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.
In addition to the pip show [package name]
command, there is pipdeptree
.
Just do
$ pip install pipdeptree
then run
$ 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]
The project is located at https://github.com/naiquevin/pipdeptree, where you will also find usage information.
这篇关于如何查找 Python 包的依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!