8

我需要通过 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/中显示的相同结果

4

1 回答 1

1

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

$ pip uninstall pydot2
$ pip install pydot>=1.2.3

脚本没有任何更改,我得到以下输出

图形

于 2017-10-13T10:14:54.243 回答