Pydot错误:无法识别文件格式“png”

时间:2015-11-12 18:26:41

标签: python python-2.7 graph graph-visualization pydot

我需要通过pydot构建一个pythonic图解决方案,并尝试运行一个简单的代码,如:

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')

用于在png文件上构建简单图形(A-B1)。 在解决了很多错误配置后,现在我得到了:

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

直到现在还无法找到适合我特定环境的直接解决方案。 有关如何修复它的任何提示? 需要适用于python 2.7和mac os x 10.9。

我当前安装的软件包:

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

我只想达到https://pythonhaven.wordpress.com/2009/12/09/generating_graphs_with_pydot/

中显示的相同结果

1 个答案:

答案 0 :(得分:1)

您可以尝试卸载pydot2并安装pydot吗?

$ pip uninstall pydot2
$ pip install pydot>=1.2.3

在脚本没有任何变化的情况下,我得到了以下输出

Graph