我下载了Graphviz 2.38 MSI版本,安装在C:\Python34文件夹下,然后运行pip安装Graphviz,一切顺利。在系统路径中我添加了C:\Python34\bin。当我试图运行一个测试脚本,在行filename= .render(filename='test'),我得到了一个消息

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

我尝试将“C:\Python34\bin\dot.exe”放在系统路径中,但它不起作用,我甚至创建了一个新的环境变量“GRAPHVIZ_DOT”,其值为“C:\Python34\bin\dot.exe”,仍然不起作用。我尝试卸载Graphviz和pip uninstall Graphviz,然后重新安装它和pip install,但没有任何工作。

整个回溯消息是:

Traceback (most recent call last):
  File "C:\Python34\lib\site-packages\graphviz\files.py", line 220, in render
    proc = subprocess.Popen(cmd, startupinfo=STARTUPINFO)
  File "C:\Python34\lib\subprocess.py", line 859, in __init__
    restore_signals, start_new_session)
  File "C:\Python34\lib\subprocess.py", line 1112, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Documents\Kissmetrics\curves and lines\eventNodes.py", line 56, in <module>
    filename=dot.render(filename='test')
  File "C:\Python34\lib\site-packages\graphviz\files.py", line 225, in render
    'are on your systems\' path' % cmd)
RuntimeError: failed to execute ['dot', '-Tpdf', '-O', 'test'], make sure the Graphviz executables are on your systems' path

有人有经验吗?


当前回答

将graphviz添加到系统路径

Windows -编辑系统环境变量。 选择环境变量。 选择路径-新建 添加graphviz的路径

例: C:\Users\AppData\Local\Continuum\anaconda3\Library\bin\graphviz

其他回答

import os
os.environ["PATH"] += os.pathsep + 'D:/Program Files (x86)/Graphviz2.38/bin/'

在windows中,只需在开头添加这两行,其中'D:/Program Files (x86)/Graphviz2.38/bin/'被替换为bin文件所在的地址。

这样问题就解决了。

OS Mojave 10.14。, Python 3.6

使用pip安装graphviz在终端有很好的反馈,但是当我试图在Jupyter笔记本上制作图形时,导致了这个错误。然后我运行了brew install graphviz,它在终端中给出了一个错误。然后我运行conda install graphviz,图形工作了。

来自@Leighton的评论:pip只会得到和你一样的路径问题,conda只会得到导入错误。

在Windows环境下,使用巧克力安装,它将确保环境变量设置正确。

choco install graphviz

Mac & Big Sur。Python 3.8.6 w/vs code。虽然它应该包含在图表包中,但我不得不手动安装graphviz。

(mymltools) ➜  infrastructure git:(master) pip list
Package    Version
---------- -------
diagrams   0.18.0
graphviz   0.13.2
Jinja2     2.11.2
MarkupSafe 1.1.1
pip        20.3.2
setuptools 51.0.0
wheel      0.36.2

运行图表失败。然后手动运行

pipenv install graphviz

效果非常好。

conda install python-graphviz

对于Windows,安装Python Graphviz,该路径将包含可执行文件。