如何确定Graphviz可执行文件在系统的PATH中?

时间:2018-09-24 04:12:16

标签: python scikit-learn anaconda graphviz

我正在Sublime Text 3上使用Python 3使用Graphviz。运行此代码时:

data = tree.export_graphviz(dtGini[55], out_file = None)
graph = graphviz.Source(data)
graph.render("testingthis")

我得到这些错误:

FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

graphviz.backend.ExecutableNotFound: failed to execute ['dot', '-Tpdf', '-O', 'testingthis'], make sure the Graphviz executables are on your systems' PATH

似乎找不到所需的文件。在Sublime Text 3中,我对Conda的用户设置为:

{
// executable is the path to anaconda's python
// this python executable is used in order to find conda
"executable": "C:/ProgramData/Miniconda3/python.exe",

// Directory in which the conda envs are stored
// Default location is the user's home directory
"environment_directory": "C:/ProgramData/Miniconda3/envs",

// configuration is the path to conda's configuration file
"configuration": "~/.condarc"
}

我在控制台中有以下环境变量:

C:\ProgramData\Miniconda3\Scripts\
C:\ProgramData\Miniconda3\
C:\ProgramData\Miniconda3\conda-meta\history
C:\Users\X\AppData\Local\conda\conda\pkgs
C:\Users\X\AppData\Local\conda\conda\pkgs\graphviz-2.38-hfd603c8_2\Library\bin
C:\Users\X\AppData\Local\conda\conda\pkgs\graphviz-2.38-hfd603c8_2\Library\bin\dot.exe

在Anaconda提示符下,当我输入Python时,按Enter键,然后输入“ import graphviz”,我没有收到任何错误。在Sublime Text 3中,如果我只有诸如graph.py

这样的文件
import graphviz

它执行时没有任何错误。

关于如何解决此问题的任何想法?它让我发疯。谢谢!

2 个答案:

答案 0 :(得分:5)

我遵循了@aprameyo roy在此处> "RuntimeError: Make sure the Graphviz executables are on your system's path" after installing Graphviz 2.38

发布的解决方案

所需的系统路径在我的PC上有所发现-我使用Ananconda安装了graphviz软件包。

将这两个命令添加到我的jupyter笔记本即可解决此问题-将C:/地址更改为您的安装位置:

(PS。我认为您需要在每次内核重新启动后重新运行它。)

# extra step to allow graphviz to be found 
import os
os.environ["PATH"] += os.pathsep + 'C:/Users/jed/Anaconda3/envs/keras/Library/bin/graphviz/'

答案 1 :(得分:0)

对我来说,解决方案是从他们的网站上下载Graphviz (即使我已经从CMD下载了它),然后更改PATH变量以反映安装位置。