Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 845
purpleostrich Avatar asked Dec 24 '22 04:12

purpleostrich


2 Answers

I followed a solution posted by @aprameyo roy here > "RuntimeError: Make sure the Graphviz executables are on your system's path" after installing Graphviz 2.38

The system path needed took some finding on my PC - I had used Ananconda to install the graphviz package.

Adding these two commands to my jupyter notebook solved the issue - change the C:/ address to your install location:

(PS. I think you will need to re-run this after every kernal restart.)

# extra step to allow graphviz to be found 
import os
os.environ["PATH"] += os.pathsep + 'C:/Users/jed/Anaconda3/envs/keras/Library/bin/graphviz/'
like image 199
JedB Avatar answered Dec 25 '22 16:12

JedB


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.

like image 20
purpleostrich Avatar answered Dec 25 '22 16:12

purpleostrich