我下载了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

有人有经验吗?


当前回答

OSX Sierra, Python 2.7, Graphviz 2.38

使用pip install graphviz和conda install graphviz都可以解决这个问题。

PIP只得到路径问题与您的相同,conda只得到导入错误。

其他回答

试着在anaconda提示符中逐一输入以下代码。

这对我很管用。

来源:https://anaconda.org/conda-forge/python-graphviz

conda install -c conda-forge python-graphviz
conda install -c conda-forge/label/broken python-graphviz
conda install -c conda-forge/label/cf201901 python-graphviz
conda install -c conda-forge/label/cf202003 python-graphviz 

然后重新启动内核!

1-首先向下下载它(图形可视化2.38)。

2-安装org.graphviz.Graphviz-2.38-graphviz-2.38。

3-现在添加“C:\Program Files (x86)\Graphviz2.38\bin”和“C:\Program Files (x86)\Graphviz2.38\bin\dot.exe”到这样的路径 注意:在Windows 8中必须使用;C:\程序文件;D:\用户;E:\文件\

Windows:

安装windows包从:https://graphviz.gitlab.io/_pages/Download/Download_windows.html 安装python graphviz包 添加“用户路径”为“C:\Program Files (x86)\ Graphviz2.38\bin” 将C:\Program Files (x86)\ Graphviz2.38\bin\dot.exe添加到“系统路径”

这对我很管用!

MACOS - Monterey的解决方案

打开:终端 执行命令pip install graphviz 运行命令:brew install graphviz 关闭:终端 开放:水蟒(Jupyter或Spyder) 执行命令import os 操作系统。environ["PATH"] += os。pathsep + "/usr/local/Cellar/graphviz/2.49.3/bin/dot"

(你必须每次都运行这个程序,直到bug被修复。) 棘手的部分是找到。文件。这是brew安装包的位置。(但它应该类似于我给出的路径。) 通过运行测试:

import mglearn as mglearn
mglearn.plots.plot_animal_tree()

希望您现在已经准备好了!

您应该在系统中安装graphviz包(而不仅仅是python包)。在Ubuntu上,你应该尝试:

sudo apt-get install graphviz