Reputation: 265
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!
Upvotes: 5
Views: 35195
Reputation: 187
In case window i resolved this problem by following below steps:
step 1. install stable_windows_10_cmake_Release_Win32_graphviz-install-2.49.3-win32.exe
step2. add path in System variable "C:\Program Files (x86)\Graphviz\bin"
2.1 On the Windows taskbar, right-click the Windows icon and select System.
2.2 In the Settings window, under Related Settings, click Advanced system settings.
2.3 On the Advanced tab, click Environment Variables.
step3. add below lines in my code
import os
import graphviz
os.environ["PATH"] += os.pathsep + 'C:/Program Files (x86)/Graphviz/bin/'
graph_data = "your graph data"
fie_ext = 'png'
temp_img = 'temp_file'
temp_img_name = "".join([temp_img, '.'+fie_ext])
my_graph= graphviz.Source(graph_data)
my_graph.render(temp_img,format=fie_ext, view=False)
Upvotes: 2
Reputation: 265
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.
Upvotes: 3
Reputation: 493
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/'
Upvotes: 10