3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

pythonのパッケージの依存関係をpydotを使って有向グラフ化

3
Posted at

前書き

以下の記事のコードをコピペして実行したら動かなかったので自分の環境用に修正したやつをメモ書き。

pythonパッケージの依存関係をgraphvizで可視化

環境

  • WSL
  • python3.6

ソースコード

import pydot
from subprocess import run, PIPE

ss = run(['pipdeptree',"-freeze"], stdout=PIPE, stderr=PIPE,
         universal_newlines=True).stdout.rstrip().split("\n")
edges = []

for s in ss:
    c = s.count(" ")
    s = s[:s.index("=")].replace(" ","")
    d[c] = s
    if c != 0:
        edges.append((d[c-2],s))
        
g = pydot.graph_from_edges(edges,directed=True)
g.write_png("pipdeptree.png")

できたもの

全部のパッケージでやると多すぎるのでpipdeptreeの出力の上から50個程度
pipdeptree.png

終わり

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?