Networkx 问题:需要安装 Graphviz / Pygraphviz (Anaconda 2021.11, WIN10x64)
Networkx issue : need to install Graphviz / Pygraphviz (Anaconda 2021.11, WIN10x64)
我正在使用 Jupyter Notebook
进行图表分析。我需要使用 Networkx
来生成 MultiDiGraph,我需要将它绘制成一棵树,但是出现了一个错误:
from networkx.drawing.nx_agraph import write_dot, graphviz_layout
write_dot(G,'test.dot')
plt.title('draw_networkx')
pos =graphviz_layout(G, prog='dot')
nx.draw(G, pos, with_labels=False, arrows=True)
ModuleNotFoundError Traceback (most recent call last)
D:\Programmes\Anaconda3\lib\site-packages\networkx\drawing\nx_agraph.py in to_agraph(N)
131 try:
--> 132 import pygraphviz
133 except ImportError as e:
ModuleNotFoundError: No module named 'pygraphviz'
The above exception was the direct cause of the following exception:
ImportError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_33384/3939344011.py in <module>
----> 1 write_dot(G,'test.dot')
2 plt.title('draw_networkx')
3 pos =graphviz_layout(G, prog='dot')
4 nx.draw(G, pos, with_labels=False, arrows=True)
D:\Programmes\Anaconda3\lib\site-packages\networkx\drawing\nx_agraph.py in write_dot(G, path)
183 Filename or file handle to write
184 """
--> 185 A = to_agraph(G)
186 A.write(path)
187 A.clear()
D:\Programmes\Anaconda3\lib\site-packages\networkx\drawing\nx_agraph.py in to_agraph(N)
132 import pygraphviz
133 except ImportError as e:
--> 134 raise ImportError("requires pygraphviz " "http://pygraphviz.github.io/") from e
135 directed = N.is_directed()
136 strict = nx.number_of_selfloops(N) == 0 and not N.is_multigraph()
ImportError: requires pygraphviz http://pygraphviz.github.io/
所以我按照中的说明进行操作,但我仍然遇到同样的错误。
也许我需要做一些其他事情来将 Pygraphviz
添加到我的 Anaconda 环境中,这样我就可以使用 networkx pygraphviz layouts
.
关于正确执行此操作的任何建议?
我有 Graphviz 2.5 二进制文件,环境变量路径填充了 bin 的路径,所以我现在可以执行上面链接的问题中显示的示例。
但是我感兴趣的代码需要 Pygraphviz
,所以我觉得我是掌握网络的第 1/N 步。
您安装了错误的 graphviz
包装器,即 python-graphviz, but you need pyGraphviz:
conda install -c conda-forge pygraphviz
我正在使用 Jupyter Notebook
进行图表分析。我需要使用 Networkx
来生成 MultiDiGraph,我需要将它绘制成一棵树,但是出现了一个错误:
from networkx.drawing.nx_agraph import write_dot, graphviz_layout
write_dot(G,'test.dot')
plt.title('draw_networkx')
pos =graphviz_layout(G, prog='dot')
nx.draw(G, pos, with_labels=False, arrows=True)
ModuleNotFoundError Traceback (most recent call last)
D:\Programmes\Anaconda3\lib\site-packages\networkx\drawing\nx_agraph.py in to_agraph(N)
131 try:
--> 132 import pygraphviz
133 except ImportError as e:
ModuleNotFoundError: No module named 'pygraphviz'
The above exception was the direct cause of the following exception:
ImportError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_33384/3939344011.py in <module>
----> 1 write_dot(G,'test.dot')
2 plt.title('draw_networkx')
3 pos =graphviz_layout(G, prog='dot')
4 nx.draw(G, pos, with_labels=False, arrows=True)
D:\Programmes\Anaconda3\lib\site-packages\networkx\drawing\nx_agraph.py in write_dot(G, path)
183 Filename or file handle to write
184 """
--> 185 A = to_agraph(G)
186 A.write(path)
187 A.clear()
D:\Programmes\Anaconda3\lib\site-packages\networkx\drawing\nx_agraph.py in to_agraph(N)
132 import pygraphviz
133 except ImportError as e:
--> 134 raise ImportError("requires pygraphviz " "http://pygraphviz.github.io/") from e
135 directed = N.is_directed()
136 strict = nx.number_of_selfloops(N) == 0 and not N.is_multigraph()
ImportError: requires pygraphviz http://pygraphviz.github.io/
所以我按照Pygraphviz
添加到我的 Anaconda 环境中,这样我就可以使用 networkx pygraphviz layouts
.
关于正确执行此操作的任何建议?
我有 Graphviz 2.5 二进制文件,环境变量路径填充了 bin 的路径,所以我现在可以执行上面链接的问题中显示的示例。
但是我感兴趣的代码需要 Pygraphviz
,所以我觉得我是掌握网络的第 1/N 步。
您安装了错误的 graphviz
包装器,即 python-graphviz, but you need pyGraphviz:
conda install -c conda-forge pygraphviz