Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pydot error: file format "png" not recognized

I need to build a pythonic graph solution through pydot and when tried to run a simple code like:

import pydot

graph = pydot.Dot(graph_type='graph')
i=1
edge = pydot.Edge("A", "B%d" % i)
graph.add_edge(edge)
graph.write_png('graph.png')

Which is designed to build a simple graph (A-B1) on the png file. After fixing a lot of misconfigurations, now I got:

Traceback (most recent call last):
  File "/Users/zallaricardo/Documents/Python/test_png.py", line 7, in <module>
    graph.write_png('graph.png')
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pydot.py", line 1809, in <lambda>
    lambda path, f=frmt, prog=self.prog : self.write(path, format=f, prog=prog))
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pydot.py", line 1911, in write
    dot_fd.write(self.create(prog, format))
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pydot.py", line 2023, in create
    status, stderr_output) )
pydot.InvocationException: Program terminated with status: 1. stderr follows: Format: "png" not recognized. Use one of:

logout

And till now could not find a straight solution to my particular environment. Any hint about how can I fix it? Need to work for python 2.7 and mac os x 10.9.

My current installed packages:

cycler==0.9.0
decorator==4.0.4
graphviz==0.4.7
matplotlib==1.5.0
networkx==1.10
numpy==1.10.1
pydot2==1.0.33
pyparsing==1.5.7
PyPDF2==1.25.1
python-dateutil==2.4.2
pytz==2015.7
six==1.10.0
wheel==0.26.0

I just would like to reach the same result shown in https://pythonhaven.wordpress.com/2009/12/09/generating_graphs_with_pydot/

like image 345
zallaricardo Avatar asked Nov 12 '15 18:11

zallaricardo


1 Answers

Could you try uninstalling pydot2 and install pydot?

$ pip uninstall pydot2
$ pip install pydot>=1.2.3

Without any change in the script, I got the following output

Graph

like image 196
Supreet Sethi Avatar answered Sep 27 '22 23:09

Supreet Sethi