2

I cannot get graphviz to install and import properly, either using conda install or pip install. I am using jupyter on anaconda.

conda install -c anaconda graphviz

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-2-0e78fd6401bd> in <module>()
----> 1 import graphviz
      2 dot_data = tree.export_graphviz(clf, out_file=None)
      3 graph = graphviz.Source(dot_data)
      4 graph.render("iris")

ModuleNotFoundError: No module named 'graphviz'

When I install using pip I can successfully import but when I run the below code, I get a very long error message that ends with the following when running graph.render:

from sklearn.datasets import load_iris
from sklearn import tree
import graphviz

iris = load_iris()
clf = tree.DecisionTreeClassifier()
clf = clf.fit(iris.data, iris.target)

dot_data = tree.export_graphviz(clf, out_file=None) 
graph = graphviz.Source(dot_data) 
graph.render("iris") 

Below is the end of the end of a long error message:

ExecutableNotFound: failed to execute ['dot', '-Tpdf', '-O', 'iris'], make sure the Graphviz executables are on your systems' PATH

I have the directory where the graphviz folders are in PATH.

Anyone have an idea what I am doing wrong?

Trexion Kameha
  • 3,362
  • 10
  • 34
  • 60

2 Answers2

0

http://www.graphviz.org/Download_windows.php

Install windows package from: http://www.graphviz.org/Download_windows.php

Install python graphviz package

Add C:\Program Files (x86)\Graphviz2.38\bin to User path

Add C:\Program Files (x86)\Graphviz2.38\bin\dot.exe to System Path

RESTART COMPUTER

Worked for me!

Trexion Kameha
  • 3,362
  • 10
  • 34
  • 60
0

If you're running Linux, you may have to run this command in addition to the Conda command (I had to do this):

sudo apt-get install graphviz

I was getting the exact same error in Pycharm and this solved it.

bingecoder
  • 141
  • 1
  • 8