[英]Graphviz Format: "jpeg" not recognized
运行以下代码(来自https://pypi.org/project/graphviz/ 的示例):
from graphviz import Digraph
dot = Digraph(comment='The Round Table', format='jpeg')
dot.node('A', 'King Arthur')
dot.node('B', 'Sir Bedevere the Wise')
dot.node('L', 'Sir Lancelot the Brave')
dot.edges(['AB', 'AL'])
dot.edge('B', 'L', constraint='false')
dot.render('test-output/round-table.gv', view=True)
结果是:
Format: "jpeg" not recognized. Use one of:
似乎graphviz无法将文件写入任何格式。 如何解决这个问题?
我的方法:(我是win10,其他操作可以跳到第2步)
将 Graphviz 的“bin/”添加到环境路径中。
D:\\software\\graphviz\\Graphviz2.44.1\\
。 它有 4 个文件夹:“bin”、“include”、“lib”、“share”D:\\software\\graphviz\\Graphviz2.44.1\\bin
到我的环境路径中cmd 运行命令“dot -c”进行配置。
dot
表示D:\\software\\graphviz\\Graphviz2.44.1\\bin\\dot.exe
。 由于第 1 步,我只需要运行dot -c
,否则,我需要运行D:\\software\\graphviz\\Graphviz2.44.1\\bin\\dot.exe -c
dot -c
表示:配置插件(使用可用的插件信息写入 $prefix/lib/graphviz/config。需要写入权限。)为您的代码添加路径:
# add
import os
path_graphviz = "D:/software/graphviz/Graphviz2.44.1/bin" # replace by your Graphviz bin path
os.environ["PATH"] += os.pathsep + path_graphviz
# origin code
from graphviz import Digraph
dot = Digraph(comment='The Round Table', format='jpeg')
dot.node('A', 'King Arthur')
dot.node('B', 'Sir Bedevere the Wise')
dot.node('L', 'Sir Lancelot the Brave')
dot.edges(['AB', 'AL'])
dot.edge('B', 'L', constraint='false')
dot.render('test-output/round-table.gv', view=True)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.