22

I try to run this example for decision tree learning, but get the following error message:

File "coco.py", line 18, in graph.write_pdf("iris.pdf") File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pydot.py", line 1602, in lambda path, f=frmt, prog=self.prog : self.write(path, format=f, prog=prog)) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pydot.py", line 1696, in write dot_fd.write(self.create(prog, format)) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pydot.py", line 1727, in create 'GraphViz\'s executables not found' ) pydot.InvocationException: GraphViz's executables not found

I saw this post about a similar error, but even when I follow their solution (uninstall and then reinstall graphviz and pydot in the opposite order) the problem continues... I'm using MacOS (Yosemite).

Any ideas? Would appreciate the help.

Community
  • 1
  • 1
Chewbacca
  • 241
  • 1
  • 3
  • 4
  • 1
    Please add to your question how you installed `graphviz` (e.g. homebrew, macports, ...). It seems that there are issues with your `PATH` variable. – cel Dec 27 '14 at 11:44
  • I used pip, so nothing special... (sudo pip install graphviz). – Chewbacca Dec 31 '14 at 12:24
  • Can I fix it by manually changing the path variable? If so, how can it be done? – Chewbacca Dec 31 '14 at 12:24
  • 7
    `Graphviz` is not a python tool. The python packages at `pypi` provide a convenient way of using `Graphviz` in python code. You still have to install the `Graphviz` executables, which are not pythonic, thus not shipped with these packages. You can install those e.g. with a general-purpose package manager such as `homebrew` – cel Dec 31 '14 at 12:38
  • Awesome it works! My eternal gratitude - thanks! – Chewbacca Dec 31 '14 at 12:51
  • @cel your comments are worth an answer, it completely answered the question. Maybe you should make them into an answer? – Akavall Jun 26 '15 at 20:27
  • @Akavall, I am not really interested in writing an answer here. If you think it would be a good idea to have an answer to this question, feel free to take my comment as a template for your answer. – cel Jun 26 '15 at 20:35
  • On Mac OS X, I suggest to start from a fresh Macports installation from source code, then install GraphViz, sudo port install graphviz – Claude COULOMBE Jul 24 '15 at 21:13

12 Answers12

32

cel, answered this in the comment:

Graphviz is not a python tool. The python packages at pypi provide a convenient way of using Graphviz in python code. You still have to install the Graphviz executables, which are not pythonic, thus not shipped with these packages. You can install those e.g. with a general-purpose package manager such as homebrew

For me personally, on ubuntu 14.04, all I had to do is:

sudo apt-get install graphviz
Akavall
  • 82,592
  • 51
  • 207
  • 251
26
brew install graphviz
pip install -U pydotplus

... worked for me on MacOSX

Mark
  • 556
  • 8
  • 12
9

On Windows 8 this solved the same problem for me:

import os     
os.environ["PATH"] += os.pathsep + 'C:/Program Files (x86)/Graphviz2.38/bin/'
  • A more permanent solution is to set the environment's `PATH` variable in the appropriate configuration file (on *nix systems this usually is `~/.bashrc`). – 0 _ Oct 17 '17 at 02:02
7

I had the same issue when installing pydot and graphviz with pip, then I found the answer here.

In particular, I first uninstalled pydot and graphviz which I separately installed using pip (using sudo pip uninstall pydot and the same for graphviz). Then, I run sudo apt-get install python-pydot which fixed the issue.

djurikom
  • 109
  • 1
  • 5
6
conda install -c anaconda graphviz        
conda install -c anaconda pydot
nbro
  • 15,395
  • 32
  • 113
  • 196
scarain
  • 191
  • 2
  • 2
4

For windows users:
1.install Graphviz
2.Add Graphviz path to PATH variable
3.Restart PyCharm or other compiler.

As of version 2.31, the Visual Studio package no longer alters the PATH variable or accesses the registry at all. If you wish to use the command-line interface to Graphviz or are using some other program that calls a Graphviz program, you will need to set the PATH variable yourself.

Dave2e
  • 22,192
  • 18
  • 42
  • 50
Matiji66
  • 709
  • 7
  • 14
4

Worked for me on Ubuntu 18.04 as well:

$ sudo apt-get install graphviz  
Kradcifer
  • 61
  • 4
2

If you are on mac operating system then you might face this issue . I have installed graphviz with pip but dint work . So I had to install it with brew again and worked for me.

use following command

brew install graphviz

Codified
  • 135
  • 9
1

I was facing the same issues, my problem got resolved using:

  1. Run the command sudo port install graphviz
  2. If error is coming for the port then first install port from below based on the version you are using https://guide.macports.org/chunked/installing.macports.html
  3. After installation of port run command sudo port install graphviz

Restart the python kernel if you are using iPython and run again.

niemmi
  • 17,113
  • 7
  • 35
  • 42
1

On mac, use Brew to install graphviz and not pip, see links:

graphviz information: http://www.graphviz.org/download/

brew installation: https://brew.sh/

So typing the following in the terminal after you install brew should work:

brew install graphviz
Liky
  • 1,105
  • 2
  • 11
  • 32
1

I did face similar issue and the way it was corrected was by changing the path.

This is what I did :

Copy paste "graphiz" path from your computer to Environment variable>Path from the control panel

Example: Graphiz path : C:\Apps\Program Files\Continuum\Anaconda2\Library\bin\graphviz)

(I had installed it on Apps folder. It could be in a diff path for you)

Setting path in Environment Variable :

Go to Control Panel>Control Panel\System and Security\System .Click Advanced Setting and then Advanced .You'll find Environment variables at bottom right. Click Path to edit and save it . Close your IDE and re open it .

It worked for me .

SEM
  • 11
  • 1
0

i would suggest avoid graphviz. use the following alternate approach

from sklearn.tree import plot_tree
plt.figure(figsize=(60,30))
plot_tree(dt, filled=True);
gourab ghosh
  • 159
  • 6