Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GraphViz's executables not found : Anaconda-3

I am trying to display the tree output , but when I run the script below, I receive an error like :

InvocationException: GraphViz's executables not found

I've searched similar topics here, but most of them are Mac related. I'm using Windows 10 64-bit operating system, and I use Anaconda-3 64 bit. I'd love to hear your suggestions on this.

#Displaying the decision tree
from sklearn import tree
#from StringIO import StringIO
from io import StringIO
#from StringIO import StringIO 
from IPython.display import Image
out = StringIO()
tree.export_graphviz(classifier, out_file=out)

import pydotplus
graph=pydotplus.graph_from_dot_data(out.getvalue())
Image(graph.create_png())

edit : I've installed graphviz and pydotplus modules again, but still now working.

like image 530
Cagdas Kanar Avatar asked Aug 17 '17 08:08

Cagdas Kanar


2 Answers

i had same problem. Here is the solution for ((Win10, Anaconda3, Jupyter notebook, python 3.x)

  1. Download and Install https://graphviz.gitlab.io/_pages/Download/Download_windows.html

  2. conda install graphviz

  3. Add graphviz installed path (C:...\graphviz\bin) to Control Panel > System and Security > System > Advanced System Settings > Environment Variables > Path > Edit > New

  4. Very Important: Restart your Jupyter notebook/machine. I tried restarting machine and it worked.

This question is answered for different OS here: Graphviz's executables are not found (Python 3.4)

like image 113
Vamshi Indla Avatar answered Nov 04 '22 02:11

Vamshi Indla


I also had a similar issue. Like Vamshi I have a similar Win10 System. My specifications; Win10, x64-based system, Anaconda3, Anaconda Navigator 1.9.6, Python 3.7 (Spyder 3.3.3 to be exact).

My solution also involves editing the PATH environment variables. Here's a step-by-step plan:

  1. Navigate to the "Environments" tab in your Anaconda explorer window. You should be able to find it in the left top side of the screen.

  2. Select the relevant environment in which you would like to install the GraphViz package. For most users this will simply be the "base (root)" environment.

  3. Once you have selected the environment in which you would like to install GraphViz, click on the Play symbol on the right-hand side of the name of your environment (e.g. "base (root)". A number of options should pop up. Just select the "Open Terminal" option from the drop-down menu.

  4. As you click "Open Terminal" a Command Prompt will be opened in the right spot for your environment. Type in the following code;


conda install graphviz

PS: You could also use pip install graphviz but in my experience it can cause conflicts with other modules installed using conda.

  1. Anaconda will now download the Graphviz package and check its compatibility with all other packages you have installed. Please be patient, this may take some time depending on your system and internet connection.

  2. Once the installation is complete, exit the Command Prompt and return to the environment in which you have installed Graphviz (probably "base (root)"). From the drop-down menu select the "installed" option to the left of the "Channels" drop-down menu. In the search box to the right type "graphviz" and check if the package has been successfully installed in your environment of choice.

  3. Now this is complete, open up a .py script that uses some Graphviz features and execute the script. Most likely you will still see a warning message such as this: "GraphViz's executables not found". In the warning message a certain file location address will be given. For me this file location was "C:\Users\David\Anaconda3\Library\bin\graphviz" but it may well be different depending on your installation process and the setup of your computer. Make sure you copy this file path.

  4. Now we need to edit our system's environment variables. Be very careful here. First, just press your Windows Start key to open up your Start menu. Afterwards, simply type "Environment variables". The first suggestion Windows should give you is this: "Edit the system environment variables". Click this link.

  5. Now you should be on the "advanced" tab of the System properties menu. Click the "Environment variables" button at the bottom of this menu -> Select path in the new menu -> Click "Edit" -> Click "New" -> In this box paste the link from your Python warning box. For me this was "C:\Users\David\Anaconda3\Library\bin\graphviz" but it may be different. Hit enter.

  6. A new line should have appeared in your path menu with the exact address you just entered.

  7. Close all programs and restart your PC. This is necessary for the new path to take effect.

  8. Reopen Anaconda Explorer, select the environment you installed GraphViz in and run Spyder from the Anaconda Explorer.

  9. Rerun your .py script that uses GraphViz features. The error message should have disappeared and the package should function as intended.

like image 21
Vermundir Avatar answered Nov 04 '22 03:11

Vermundir