繁体   English   中英

Graphviz 格式:无法识别“jpeg”

[英]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步)

  1. 将 Graphviz 的“bin/”添加到环境路径中。

    • 我的 Graphviz 安装路径: D:\\software\\graphviz\\Graphviz2.44.1\\ 它有 4 个文件夹:“bin”、“include”、“lib”、“share”
    • 所以我将D:\\software\\graphviz\\Graphviz2.44.1\\bin到我的环境路径中
  2. 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。需要写入权限。)
  3. 为您的代码添加路径:

# 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)
  1. 我在我的电脑上成功了。 这是结果

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM