GraphViz not working when imported inside PydotPlus (`GraphViz's executables not found`) 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 &lt;module&gt;
    Image(graph.create_png())
  File "/home/philippe/.local/lib/python3.6/site-packages/pydotplus/graphviz.py", line 1797, in &lt;lambda&gt;
    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.
See: Graphviz's executables are not found (Python 3.4) and graphviz package doesn't add executable to PATH on windows #1666 and Problem with graphviz #1357 - it's a reoccurring problem (for that program) with the PATH environment variable settings. Installing particular versions, or in a particular order, or manually adding a PATH fixes the problem.

It's best if the Package sets the PATH correctly and removes it when you uninstall the Package (so you don't get too long a PATH - which usually won't happen). Setting it manually prevents future breakage and forces it to work, but you need to manually remove the extra text if you uninstall the Package.

Here's the advice from those three links:


pip install graphviz
conda install graphviz


or

You need to run

conda install python-graphviz

instead of

pip install graphviz

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

or


Download and install graphviz-2.38.msi (use the newest version) from
https://graphviz.gitlab.io/_pages/Download/Download_windows.html
Set the path variable


&nbsp; &nbsp; &nbsp; &nbsp; (a) Control Panel > System and Security > System > Advanced System Settings > Environment Variables > Path > Edit

&nbsp; &nbsp; &nbsp; &nbsp; (b) add 'C:\Program Files (x86)\Graphviz2.38\bin'