找不到Graphviz的可执行文件(Python3.4)

2024-05-12 19:30:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我在Windows7上运行Python3.4。我正在尝试将Python接口用于graphviz。这是我打算运行的脚本:

from graphviz import Digraph
import pydotplus

dot = Digraph(comment='The Round Table')

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')

print(dot.source)
dot.render('test-output/round-table.gv', view=True)

运行时出现以下错误:

RuntimeError: failed to execute ['dot', '-Tpdf', '-O', 'test-output/round-table.gv'], make sure the Graphviz executables are on your systems' path

现在我确信我已经正确安装了正确的依赖项。我首先尝试设置正确的环境变量。graphviz可执行文件位于C:\程序文件(x86)\ Graphviz2.37\bin中,因此我转到了环境变量部分。这里有两个部分:用户变量和系统变量。在“系统变量”下,我单击了路径,然后单击Edit,并将C:\程序文件(x86)Graphviz2.37\bin添加到字符串末尾并保存。这并没有消除错误。

然后,在回答given here之后,我卸载了pydot(实际上我在这里使用了pydotplus)并重新安装了它,但仍然没有成功。

我已经尝试了几个小时来解决这个问题,整个路径变量的事情只是混乱和令人沮丧。


Tags: thetestimportnodeoutput错误tableplus
3条回答

在我的例子中(Win10,Anaconda3,Jupyter笔记本)在"conda install graphviz"之后,我必须添加到路径:C:\Users\username\Anaconda3\Library\bin\graphviz

要修改路径,请转到Control Panel > System and Security > System > Advanced System Settings > Environment Variables > Path > Edit > New

在win10中的jupyter(ipython)笔记本上,我在安装graphviz之后通过pip install graphviz解决了这个问题

我在Ubuntu 16.04上也遇到了这个问题。

通过在我已经执行的pip安装之外运行sudo apt-get install graphviz进行修复。

相关问题 更多 >