I've been trying to make these packages work for quite some time now but with no success. Basically the error is:
GraphViz's Executables not found
EDIT: I had not posted a terminal log
with the error originally. I'm using Ubuntu
now so I won't be able to reproduce the exact same error I got in the past (a year ago, so far away in the past...). However, I've been experiencing a similar --- if not the same --- error in my current setup; even while using a virtual environment with pipenv
. The error seems to come from lines that were described in @张乾元's answer:
Traceback (most recent call last):
File "example.py", line 49, in <module>
Image(graph.create_png())
File "/home/philippe/.local/lib/python3.6/site-packages/pydotplus/graphviz.py", line 1797, in <lambda>
lambda f=frmt, prog=self.prog: self.create(format=f, prog=prog)
File "/home/philippe/.local/lib/python3.6/site-packages/pydotplus/graphviz.py", line 1960, in create
'GraphViz\'s executables not found')
pydotplus.graphviz.InvocationException: GraphViz's executables not found
I've tried to install GraphViz
via 2 different ways: via pip install graphviz
and through the .msi
package (and also tried to install pydot
, pydotplus
and graphviz
in many different orders).
The code I'm trying to run is simply a dot-to-png
converter for the Iris Dataset.
from sklearn.tree import DecisionTreeClassifier
import sklearn.datasets as datasets
from sklearn.externals.six import StringIO
from sklearn.tree import export_graphviz
import pandas as pd
import pydotplus
from IPython.display import Image
iris = datasets.load_iris()
df = pd.DataFrame(iris.data, columns = iris.feature_names)
y = iris.target
dtree = DecisionTreeClassifier()
dtree.fit(df,y)
dot_data = StringIO()
export_graphviz(
dtree,
out_file = dot_data,
filled = True,
rounded = True,
special_characters = True
)
graph_1 = pydotplus.graph_from_dot_data(dot_data.getvalue())
Image(graph_1.create_png())
In Jupyter Notebooks
and in Atom
, the system seems to be looking for GraphViz
inside pydotplus
, as it points to ~\Anaconda3\lib\site-packages\pydotplus\graphviz.py
. Shouldn't it be the other way around?
Lastly, I just want to point out that I've already tried adding GraphViz
's path to the system's PATH
using C:\Users\Philippe\Anaconda3\Library\bin\graphviz
.
pipenv
,virtualenv
orDocker Containers
, though I haven't properly checked it yet. $\endgroup$