user10461026
user10461026

Reputation:

Jupyter: InvocationException: GraphViz's executables not found

I tried to visualize a Decision Tree on Jupyter Notebook (Python version 3.6.10) but was unable to.

from sklearn import tree
model = tree.DecisionTreeClassifier(criterion='entropy') 
model=tree.DecisionTreeClassifier()
model.fit(trainData,trainLabel)
model.score(trainData,trainLabel)
predicted= model.predict(testData)

from io import StringIO
dot_data = StringIO() 
tree.export_graphviz(model, out_file=dot_data) 
graph = pydotplus.graph_from_dot_data(dot_data.getvalue()) 
Image(graph.create_png())

I keep getting "GraphViz's executables not found". Even after checking other threads about the same problem, adding the environment variable, and restarting Jupyter, I still have this problem.

UPDATE 12/13/2020: I was able to fix this problem. This is what I did:

Below the block with my other import statements, I put a block like this:

import os

os.environ['PATH'] = os.environ['PATH']+';'+os.environ['CONDA_PREFIX']+r"\Library\bin\graphviz"

Upvotes: 1

Views: 5856

Answers (1)

BigData-Guru
BigData-Guru

Reputation: 1261

I was getting the same issue. This needs some environment variable to set. So what I would suggest is run the below command

conda install python-graphviz

instead of

pip install graphviz

to get these bindings, which also work with conda's Graphviz package.

Upvotes: 2

Related Questions