【问题标题】:Where do I add Graphviz's Executable on a Mac我在哪里可以在 Mac 上添加 Graphviz 的可执行文件
【发布时间】: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


【解决方案1】:

我尝试了这些命令来帮助我在我的 Mac 上找到 DOT 文件路径。它不是:“/usr/local/bin/dot”在我的系统上。

dot -V

dot - graphviz version 2.49.2

which dot

/opt/homebrew/bin/dot

我已经安装了 Graphviz,但我仍然无法找到正确的路径。我正在使用 Protege,我不得不修改 OwlViz 的路径,因为它在 (0,0) 处显示整个层次结构。我将通过运行 which dot 命令获得的路径复制到首选项对话框上的 OWLViz 选项卡,然后重新启动 protege,它运行良好!祝你好运!

【讨论】:

    【解决方案2】:

    诊断表明 dot 不在您的 $PATH 中,它没有出现在该环境变量提到的任何目录中。您希望尝试以下命令会报告一些版本号:

    $ dot -V
    dot - graphviz version 2.40.1 (20161225.0304)
    $
    $ which dot
    /usr/local/bin/dot
    $
    $ echo $PATH | tr : ' ' | fmt -w1 | grep local
    /usr/local/bin
    

    如果您还没有使用 Brew,那么您应该这样做。这是将这个程序和许多其他程序放到您的 Mac 上的最简单方法。访问https://brew.sh/ 并按照说明进行操作。然后输入:

    $ brew install graphviz
    ...
    $ /usr/local/bin/dot -V
    

    这应该可以正常工作。如果dot -V 说“未找到”,那么只需将正确的目录附加到您的 PATH:

    $ export PATH="${PATH}:/usr/local/bin"
    

    如果你的 bash shell 可以运行它,那么你的 python 程序应该也可以。

    【讨论】:

    • 感谢您帮助我。我已经安装了自制软件,但这没关系,因为我不明白它是如何工作的。当我输入命令/usr/local/bin/dot -V 时,我收到错误消息:/usr/local/bin/dot: No such file or directory。当我输入export PATH="${PATH}:/usr/local/bin" 时,我没有收到错误消息,但程序无法运行。我尝试用 PATH 替换模块所在的路径:/Users/me/PycharmProjects/inference_engine2/inference2/proofs/other/ 但这给出了消息:bad substitution
    • 听起来你的 Mac 上没有安装 dot。使用$ brew install graphviz将其安装在默认位置/usr/local/bin。
    • 我输入了brew install graphviz,一切正常。我确实收到了这条消息 Error: The following directories are not writable by your user: /usr/local/share/man/man3 /usr/local/share/man/man5 /usr/local/share/man/man7 但我不确定这是否相关。
    • 当我写信时:echo $PATH 我得到:/Library/Frameworks/Python.framework/Versions/3.6/bin:/usr/local/bin/dot
    • 简而言之,在文档中它说:“确保包含 dot 可执行文件的目录位于系统路径上。”我只是不明白这意味着什么。
    【解决方案3】:

    问题解决了。我花了一段时间才弄清楚我必须先下载一些非 Python 软件,然后才能让 Python 软件工作。

    brew install graphviz
    

    是第 1 步,我之前已经这样做了,但我收到了一条错误消息。它告诉我更改某些文件的所有权,所以我这样做了。然后尝试了

    brew install graphviz
    

    再次成功。

    【讨论】:

      猜你喜欢
      • 2013-11-08
      • 1970-01-01
      • 1970-01-01
      • 2013-05-26
      • 1970-01-01
      • 1970-01-01
      • 2019-02-24
      • 1970-01-01
      • 2020-06-21
      相关资源
      最近更新 更多