Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pydot and graphviz error: Couldn't import dot_parser, loading of dot files will not be possible

When I run a very simple code with pydot

import pydot graph = pydot.Dot(graph_type='graph')  for i in range(3):    edge = pydot.Edge("king", "lord%d" % i)   graph.add_edge(edge)  vassal_num = 0 for i in range(3):   for j in range(2):     edge = pydot.Edge("lord%d" % i, "vassal%d" % vassal_num)     graph.add_edge(edge)     vassal_num += 1  graph.write_png('example1_graph.png') 

It prints me the error message:

Couldn't import dot_parser, loading of dot files will not be possible. 

I'm using python 2.7.3

like image 760
Sadik Avatar asked Apr 11 '13 14:04

Sadik


People also ask

What is Pydot in Python?

Pydot is a Python library, also written in Python, that "serves as a graphical interface to Graphviz, an open source graph visualization software. GraphViz is written in DOT language, but Pydot provides the ability to parse and dump data, between Python and DOT."[

How do I add Pydot to path?

Type conda install pydot graphviz in cmd, and then add the executables location directory C:\Anaconda3\pkgs\graphviz-2.38-hfd603c8_2\Library\bin\graphviz to your system path variable. That works! It works!


2 Answers

Answer for pydot >= 1.1:

The incompatibility of (upstream) pydot has been fixed by 6dff94b3f1, and thus pydot >= 1.1 will be compatible with pyparsing >= 1.5.7.


Answer applicable to pydot <= 1.0.28:

For anyone else who comes across this, it is due to the changes in pyparsing from 1.x to the 2.x release. To install pydot using pip, first install the older version of pyparsing:

pip install pyparsing==1.5.7 pip install pydot==1.0.28 

If you did not install pyparsing using pip, but instead used setup.py, then have a look at this solution to uninstall the package. Thanks @qtips.

like image 63
Jonathan Avatar answered Oct 02 '22 17:10

Jonathan


There is a new package in the pip repo called pydot2 that functions correctly with pyparsing2. I couldn't downgrade my packages because matplotlib depends on the newer pyparsing package.

Note: python2.7 from macports

like image 23
Dana the Sane Avatar answered Oct 02 '22 16:10

Dana the Sane