Graphviz格式:"jpeg"未识别 [英] Graphviz Format: "jpeg" not recognized
本文介绍了Graphviz格式:"jpeg"未识别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
运行以下代码(示例来自 https://pypi.org/project/graphviz/):
Running the following code (example from 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无法将文件写入任何格式.该如何解决?
It seems like graphviz cannot write a file to any format. How to solve this?
推荐答案
我的方法:(我是win10,其他操作可能会跳到步骤2)
My method: (I'm win10, other op may skip to step 2)
-
添加"bin/" Graphviz进入环境路径.
Add "bin/" of Graphviz into environment path.
- 我的Graphviz安装路径:
D:\software\graphviz\Graphviz2.44.1\
.它具有4个文件夹:"bin","include","lib","share" - 因此我将
D:\software\graphviz\Graphviz2.44.1\bin
添加到我的环境路径中
- My Graphviz installation path:
D:\software\graphviz\Graphviz2.44.1\
. It has 4 folders: "bin","include","lib","share" - So I add
D:\software\graphviz\Graphviz2.44.1\bin
to my environment path
cmd运行命令点-c";进行配置.
cmd run command "dot -c" to config.
-
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.需要写权限.)
dot
meansD:\software\graphviz\Graphviz2.44.1\bin\dot.exe
. Due to step 1, I just need to rundot -c
, otherwise, I need to runD:\software\graphviz\Graphviz2.44.1\bin\dot.exe -c
dot -c
means: Configure plugins (Writes $prefix/lib/graphviz/config with available plugin information. Needs write privilege.)
添加代码路径:
# 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)
- 我在计算机上取得了成功. 这是结果
- I success on my computer. here is result
这篇关于Graphviz格式:"jpeg"未识别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文