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

pur*_*ich 1 python graphviz scikit-learn anaconda

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

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

我得到这些错误:

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
Run Code Online (Sandbox Code Playgroud)

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

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

我可以从控制面板中获取以下环境变量:

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
Run Code Online (Sandbox Code Playgroud)

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

import graphviz
Run Code Online (Sandbox Code Playgroud)

它执行没有任何错误。

关于如何解决这个问题有什么想法吗?它让我发疯。谢谢!

Jed*_*edB 5

安装Graphviz 2.38后,我遵循了@aprameyo roy在此处发布的解决方案> “ RuntimeError:确保Graphviz可执行文件在系统路径上”

我的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/'
Run Code Online (Sandbox Code Playgroud)


pur*_*ich 3

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


归档时间:

查看次数:

4565 次

最近记录:

6 年,8 月 前