Согласно справке в pipdeptree -h
, опция --json-tree
переопределяет опцию -p
:
--json-tree Display dependency tree as json which is nested the
same way as the plain text output printed by default.
This option overrides all other options (except
--json).
Так что, к сожалению, похоже, что дерево одного пакета отображается как jsonобычно не возможно.Использование только опции -p
без --json-tree
работает как положено:
$ pipdeptree -p numpy
numpy==1.16.2
Но, к сожалению, это просто обычный вывод.
Конечно, вы всегда можете взломать его вместе, импортировав pipdeptree вскрипт:
import pipdeptree
import json
pkgs = pipdeptree.get_installed_distributions()
dist_index = pipdeptree.build_dist_index(pkgs)
tree = pipdeptree.construct_tree(dist_index)
json_tree = json.loads(pipdeptree.render_json_tree(tree, indent=0))
print([package for package in json_tree if package['package_name'] == 'numpy'][0])
вывод
{'required_version': '1.16.2', 'dependencies': [], 'package_name': 'numpy', 'installed_version': '1.16.2', 'key': 'numpy'}
Исходный код здесь, если вы хотите попробовать что-то вроде этого: https://github.com/naiquevin/pipdeptree/blob/master/pipdeptree.py