【发布时间】:2018-09-24 04:12:15
【问题描述】:
我正在使用 Python 3 在 Sublime Text 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 时,按回车键,然后输入“import graphviz”,我没有收到任何错误。在 Sublime Text 3 中,如果我只有一个类似 graph.py 的文件
import graphviz
它执行没有任何错误。
关于如何解决这个问题的任何想法?它快把我逼疯了。谢谢!
【问题讨论】:
-
你需要指定Graphviz的'bin'库的路径。下面的例子。 import os os.environ["PATH"] += os.pathsep + 'C:/Program Files (x86)/Graphviz2.38/bin/'
标签: python scikit-learn anaconda graphviz