gpt4 book ai didi

python - Pydot 错误 : file format "png" not recognized

转载 作者:太空狗 更新时间:2023-10-29 21:10:59 25 4
gpt4 key购买 nike

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

最佳答案

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

$ pip uninstall pydot2
$ pip install pydot>=1.2.3

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

Graph

关于python - Pydot 错误 : file format "png" not recognized,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33678636/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com