1

I'm trying to export a dot file from networkx to visualize an example multigraph using pydot in Spyder, like so:

import networkx as nx

G = nx.MultiGraph()
for i in range(10):
    for j in range(3):
        G.add_edge(i, i+1, line=j)

nx.draw_networkx(G,pos=nx.spring_layout(G))

from networkx.drawing.nx_pydot import write_dot
write_dot(G,'multi.dot')

import pydot
(graph,) = pydot.graph_from_dot_file('multi.dot')
graph.write_png('multi.png')

Although the dot file is exported as expected, I get this error on the write_png line: FileNotFoundError: [WinError 2] "dot" not found in path.

I installed Graphviz and PyDot in the WinPython command prompt with:

pip install graphviz
pip install pydot

as per similar questions I've seen here. I've also tried restarting both Spyder and the command prompt itself, with no change. What could be causing this?

James Todd
  • 11
  • 2
  • IIRC, the pip package graphviz contains only the Python bindings, not Graphviz itself, so you'll want to get that as well somehow. If you're using conda, you can get Graphviz through the conda package `graphviz` (and the bindings through `python-graphviz`). – fuglede Nov 09 '19 at 18:39

0 Answers0