Python Graphviz格式:“;jpeg";不认识

Python Graphviz格式:“;jpeg";不认识,python,jpeg,graphviz,dot,Python,Jpeg,Graphviz,Dot,运行以下代码(来自的示例): 结果: Format: "jpeg" not recognized. Use one of: graphviz似乎无法将文件写入任何格式。如何解决这个问题?我的方法:(我是win10,其他op可能会跳到步骤2) 将Graphviz的“bin/”添加到环境路径中 我的Graphviz安装路径:D:\software\Graphviz\Graphviz 2.44.1\。它有4个文件夹:“bin”、“include”、“lib”、“share” 因此,我将D:\sof

运行以下代码(来自的示例):

结果:

Format: "jpeg" not recognized. Use one of:
graphviz似乎无法将文件写入任何格式。如何解决这个问题?

我的方法:(我是win10,其他op可能会跳到步骤2)

  • 将Graphviz的“bin/”添加到环境路径中

    • 我的Graphviz安装路径:
      D:\software\Graphviz\Graphviz 2.44.1\
      。它有4个文件夹:“bin”、“include”、“lib”、“share”
    • 因此,我将
      D:\software\graphviz\graphviz 2.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。需要写入权限。)
  • 将路径添加到代码:

  • 我在电脑上取得了成功。

  • 离题了,但是:将图形图像存储为JPEG是一个非常糟糕的主意。考虑使用矢量格式,或者,如果你想光栅化,像PNG这样的无损格式。看起来JPEG在你的DOT版本中是不被允许的。当在命令窗口中发出命令时,
    dot-v
    给出了什么?(同时给出
    C
    以再次退出dot程序)。以管理员身份运行
    dot-C
    修复了格式无法识别的错误。我还必须将dot.exe复制到neato.exe才能使用neato。谢谢
    Format: "jpeg" not recognized. Use one of:
    
    # 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)