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

有人有经验吗?


当前回答

我在macOS Catalina 10.15.3上,我有一个类似的错误:ExecutableNotFound: failed to execute ['dot', '-Tsvg'],请确保Graphviz可执行文件在您的系统的PATH上

固定它与:

pip3安装graphviz和酿造安装graphviz

请注意,pip3安装只会返回成功消息成功安装graphviz-0.13.2,所以我们仍然需要运行brew install来获得graphviz 2.42.3(截至2020年3月10日下午6点)。

其他回答

#Write this on anaconda prompt in admin mode
conda install -c anaconda 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

#check dot -v in window's cmd prompt
C:\WINDOWS\system32>dot -V
dot - graphviz version 2.38.0 (20140413.2041)
(this means graphviz installed successfully)

#Add path to sys and user eve variables
PATH
C:\Anaconda3\pkgs\graphviz-2.38-hfd603c8_2\Library\bin
(search bin folder of graphviz and then copy n paste path in env variables)

#Re-run all cmds in jyupter notebook
#if error occurs (less chances)
#then 
#Restart anaconda and again run all cmds in jyupter notebook
eg.
import graphviz as gp
with open("tree.dot") as f:
    dot_read=f.read()
display(gp.Source(dot_read))

这显示了一些路径问题:

pip install graphviz

所以这对我很有用:

sudo apt-get install graphviz

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

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

这个应该可以解决MacOS上的问题:

brew install graphviz

我在Linux上使用Jupyter时也遇到了同样的问题。

为了解决这个问题,我在python sys.path中添加了点库

第一:检查dot是否安装,

然后: 找到他的路径:dot -> /local/notebook/miniconda2/envs/ik2/bin/dot

最后在python脚本中: sys.path.append(“/地方/笔记本/ miniconda2 / env / ik2 / bin /点”)