【发布时间】:2019-07-24 19:20:52
【问题描述】:
我正在尝试使用Graphviz,但收到错误消息:
graphviz.backend.ExecutableNotFound: failed to execute ['dot', '-Tpdf', '-O', 'test-output/aoc.gv.pdf'], make sure the Graphviz executables are on your systems' PATH
我正在运行的代码是从文档中剪切和粘贴的:
from graphviz import Digraph, Graph
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')
dot.render('test-output/aoc.gv.pdf')
该文件将输出到正确的文件夹,该文件在那里,它有 170 个字节,但它不会打开。我已经尝试过其他扩展,例如“gv”,但它们也不起作用。我正在使用最新版本的Graphviz,它是 0.10.1,我尝试在 PC 上打开这个文件,但它在 PC 上也不起作用(我有一台 Mac)。这个问题类似于
Graphviz's executables are not found (Python 3.4)
和
Why is pydot unable to find GraphViz's executables in Windows 8?
但是,我理解这些帖子存在重大障碍。第一,我对 Python 是如何在计算机上执行的了解很少,所以我什至不知道环境变量是什么。其次,当他们提到计算机的 PATH 时,我只能假设他们正在谈论正在执行 Graphviz 模块的文件的目录,但我不确定。所以我添加了这行代码:
import sys
str1 = "/library/frameworks/python.framework/versions/3.6/lib/python3.6/site-packages/graphviz/"
sys.path.append(str1)
但这不起作用。第三,如果我要实现这一步:
将此字符串添加到变量值列表的末尾(包括分号):;C:\Program Files (x86)\Graphviz2.34\bin
然后我必须将它翻译成它的 Mac 对应物,但我做不到。任何帮助将不胜感激。
【问题讨论】:
-
您是否安装了实际的 Graphviz(不是 python 包,而是实际的程序)?例如
brew install graphviz? -
阅读 linfo.org/path_env_var.html 以了解 PATH 的工作原理。
brew通常会安装/usr/local/bin下的所有内容。 -
Homebrew 在哪里安装 Graphviz?我还没有找到一个包含这些重要信息的网站!它不在 /Applications 中。
标签: python-3.x graphviz