Search code examples
pythonscikit-learnanacondagraphviz

How do I make sure the Graphviz executables are on my system's PATH?


I am working with Graphviz using Python 3 on Sublime Text 3. When I run this code:

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

I get these errors:

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

It looks like it can't find the files it needs. In Sublime Text 3, my user settings for Conda are:

{
// 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"
}

I have these environment variables from my control panel:

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

In the Anaconda prompt, when I enter Python, hit enter, and then type in "import graphviz" I get no error. In Sublime Text 3, if I just have a file like graph.py

import graphviz

It executes without any errors.

Any ideas on how I can solve this? It's driving me nuts. Thank you!


Solution

  • The solution for me was downloading Graphviz from their website (even though I had already downloaded it from the CMD), and then changing the PATH variable to reflect the location of the installation.