Pydot error: file format "png" not recognized
Asked Answered
A

1

8

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/

Allometry answered 12/11, 2015 at 18:26 Comment(4)
Try dumping the dot file with write_raw, and running the command manually, i.e. dot -Tjpeg -o/output/file -v /your/dot/file. What is the output of that command?Firepower
@Firepower I'm not sure what you mean by dumping the dot file with write_raw but the output for the dot -Tjpeg - ... is: dot - graphviz version 2.38.0 (20140413.2041) Format: "jpeg" not recognized. Use one of: Allometry
Is the Use one of: list empty? What about dot -Tjpg:? How did you install graphviz, from a dpkg or compiled it (with Homebrew/Macports)? Maybe your are hitting this bug, please try graphviz 2.39.Firepower
For dot -Tjpg: the output is Format: "jpg:" not recognized. Use one of:. All the lists Use one of: mentioned are empty. I used pip install graphviz through terminal, and after installing graphviz 2.39, running finally rendered the png file. Thanks @memoselyk! Now the output for dot -Tjpeg - commands are full of graphviz stuff.Allometry
T
1

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

Tobytobye answered 13/10, 2017 at 10:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.