57

I am running Python3.4 on Windows 7. I am trying to use the Python interface for graphviz. This is a script I intend to run:

from graphviz import Digraph
import pydotplus

dot = Digraph(comment='The Round Table')

dot.node('A', 'King Arthur')
dot.node('B', 'Sir Bedevere the Wise')
dot.node('L', 'Sir Lancelot the Brave')
dot.edges(['AB', 'AL'])
dot.edge('B', 'L', constraint='false')

print(dot.source)
dot.render('test-output/round-table.gv', view=True)

I get the following error at runtime:

RuntimeError: failed to execute ['dot', '-Tpdf', '-O', 'test-output/round-table.gv'], make sure the Graphviz executables are on your systems' path

Now I am sure I have properly installed the correct dependencies. I first tried to set the correct environment variables. The graphviz executables are located at C:\Program Files (x86)\Graphviz2.37\bin so I went to the Environment Variables section. There are two sections there: User Variables and System Variables. Under System Variables I clicked on Path and then clicked Edit and added ;C:\Program Files (x86)\Graphviz2.37\bin to the end of the string and saved. This didn't clear the error.

Then, following the answer given here I uninstalled pydot (actually I use pydotplus here) and re-installed it again, but still no success.

I have been trying for hours to fix this and the whole PATH variable thing is just confusing and frustrating.

Community
  • 1
  • 1
Morteza R
  • 2,229
  • 4
  • 20
  • 31

31 Answers31

46

I also had this problem on Ubuntu 16.04.

Fixed by running sudo apt-get install graphviz in addition to the pip install I had already performed.

tom4everitt
  • 581
  • 4
  • 6
38

In my case (Win10, Anaconda3, Jupyter notebook) after "conda install graphviz" I have to add to the PATH: C:\Users\username\Anaconda3\Library\bin\graphviz

To modify PATH goto Control Panel > System and Security > System > Advanced System Settings > Environment Variables > Path > Edit > New

Randy
  • 9,419
  • 5
  • 39
  • 56
Silvia Bakalova
  • 381
  • 3
  • 3
29

Because Mac OS has not been mentioned I will add that I had the same problem on OS X Yosemite, the solution I found was to do brew install graphviz

This solved the problem, not sure if I shouldn't have just edited one of the other answers in this list, because they all seem to be the same answer, just install an official package in addition to the Python Library.

Veggiet
  • 455
  • 4
  • 10
  • 3
    Thanks a lot, it also works on OS X Mojave, it seems that the pip install command only deals with the paths of the tool as a wrapper, but the real executables have to be installed manually, with brew in this case. – le0diaz Nov 06 '18 at 23:23
18

On jupyter(ipython) notebook with anaconda in win10 I solved the problem by conda install graphviz after I had installed graphviz by pip install graphviz

Plory.Truck
  • 181
  • 1
  • 5
  • 1
    windows 8.1 x64 w/ Python 3.5.1 :: Anaconda 4.0.0 (64-bit) after pip install was able to conda install and this solved my issue. it's kind of misleading that it says to only do pip install to get started with graphviz, because you definitely need to install both ways – flux9998 May 15 '16 at 07:37
  • This method worked for me on widnows 10 x64; conda=22.11.1; anaconda=3; python=3.9.12. Prior to this step, I added the graphviz path to the environment path, but it did not work. – Mohammed Jan 21 '23 at 17:03
10

I solved it installing directly from https://graphviz.gitlab.io/_pages/Download/Download_windows.html and including in windows path:

C:\Program Files (x86)\Graphviz2.38\bin

C:\Program Files (x86)\Graphviz2.38

After I restart windows

outlier229
  • 481
  • 1
  • 7
  • 18
Aris
  • 156
  • 1
  • 13
  • This worked for me with just the first line added to the path and without the need to restart Windows (just the IDE). Thanks for the tip! – Irina Feb 13 '18 at 20:24
8

If you are on Win10, install Graphviz (link) and then use following command to add the path.

import os
os.environ["PATH"] += os.pathsep + 'C:\Program Files (x86)\Graphviz2.38/bin/'
hellomynameisA
  • 546
  • 1
  • 7
  • 28
Regi Mathew
  • 2,603
  • 3
  • 24
  • 38
6

when you add C:\Program Files (x86)\Graphviz2.38\bin to PATH, then you must close your IDE enviroment such as spyder and restart, you'll solve the "RuntimeError:make sure the Graphviz executables are on your systems' path"

JackChen
  • 71
  • 1
  • 2
6

Just install

conda install graphviz

then install

conda install -c conda-forge pydotplus
Shersha Fn
  • 1,511
  • 3
  • 26
  • 34
6

I encountered the same problem in Jupyter Notebook. Add this, and you are good to go.

import os

os.environ['PATH'] = os.environ['PATH']+';'+os.environ['CONDA_PREFIX']+r"\Library\bin\graphviz"
Geekquad
  • 55
  • 1
  • 5
5

To solve this problem,when you install graphviz2.38 successfully, then add your PATH variable to system path.Under System Variables you can click on Path and then clicked Edit and added ;C:\Program Files (x86)\Graphviz2.38\bin to the end of the string and saved.After that,restart your pythonIDE like spyper,then it works well.

Don't forget to close Spyder and then restart.

JackCHEN
  • 51
  • 1
  • 1
5

Please note that I am using windows 10. some of the following may or may not applicable for other versions of windows or operating systems:

** Note 2: **
"the Graphviz bin file address on your system" can be C:\Program Files (x86)\Graphviz2.38\bin or any other path you installed Graphviz there.

We have problem not only with Graphviz but also with other external EXE files we want to use in Jupyter.
The reason is when jupyter wants to import a package it looks in working directory to find it and when it fails to find the package it returns such errors.
What we can do is tackle this is as follows:
1) check if the Graphviz is installed on your system and if not you can download and install it from:

https://graphviz.gitlab.io/_pages/Download/Download_windows.html
and then install it. When you installing Graphviz, keep in mind where (in which folder) you are installing it. If you see the above error when you use

import graphviz

then you have several options:

2) you can call the .exe file in the ipynb via

import os
os.environ["PATH"] += os.pathsep + r'the Graphviz bin file address on your system'

It is my experience that it is only works for the same ipynb that I am working with and every time that I open the notebook I need to call this lines of code.

3) If you want the Jupyter where to find the exe file, you need to set environmenal path.
In windows 10 you can do this going to:
Control Panel > System and Security > System > Advanced System Settings > Environment Variables > Path > Edit > New
and then add the "the Graphviz bin file address on your system" In windows 8 or lower go to :
Control Panel > System and Security > System > Advanced System Settings > Environment Variables
and then add the ;(semicolon) + "the Graphviz bin file address on your system" to the end of path string
Note: remember to restart your machine.

4) and even this does not work, define a variable going to:
Control Panel > System and Security > System > Advanced System Settings > Environment Variables and then:

Start to define an environmental variable

Then define a variable as this: Remember to name the variable Graphviz

Remember to name the variable Graphviz. At last restart your PC and hope it works.

Afshin Amiri
  • 3,438
  • 1
  • 20
  • 21
4

I tried setting up Environment variable. Didn't work.I am in Windows environment Combining above methods worked for me :

  1. Downloaded graphviz-2.38.zip from https://graphviz.gitlab.io/_pages/Download/Download_windows.html

  2. Copied the extracted folder into C:\Users\\AppData\Local\Continuum\anaconda3\pkgs\Graphviz2.38

  3. I called the Graphviz location in my code

    Build the classifier

    import sklearn.datasets as datasets
    import pandas as pd
    from sklearn.tree import DecisionTreeClassifier
    iris=datasets.load_iris()
    df=pd.DataFrame(iris.data, columns=iris.feature_names)
    y=iris.target
    
    dtree=DecisionTreeClassifier()
    dtree.fit(df,y)
    

    Build the tree

    from sklearn.externals.six import StringIO  
    from IPython.display import Image  
    from sklearn.tree import export_graphviz
    import pydotplus
    import graphviz
    import os
    os.environ\["PATH"\] += os.pathsep + 'C:/Users/tstusr/AppData/Local/Continuum/anaconda3/pkgs/Graphviz2.38/bin'
    
    dot_data = StringIO()
    export_graphviz(dtree, out_file=dot_data,  
                    filled=True, rounded=True,
                    special_characters=True)
    graph = pydotplus.graph_from_dot_data(dot_data.getvalue())  
    Image(graph.create_png())
    

    Here is how the tree looks:

enter image description here

Jagannath Banerjee
  • 2,081
  • 1
  • 9
  • 7
3

As it appears, Graphviz2.37 is known to have problems with the PATH variable on windows. I uninstalled it, removed the environment variables associated with it and instead downloaded and installed the newer beta version 2.39 and it now works like a charm.

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Morteza R
  • 2,229
  • 4
  • 20
  • 31
3

For windows 8.1 & python 2.7 , I fixed the problem by following below steps

1 . Download and install graphviz-2.38.msi http://www.graphviz.org/pub/graphviz/stable/windows/graphviz-2.38.msi

2 . Set the path variable

  • Control Panel > System and Security > System > Advanced System Settings > Environment Variables > Path > Edit
  • add 'C:\Program Files (x86)\Graphviz2.38\bin'
Jayani Sumudini
  • 1,409
  • 2
  • 22
  • 29
2

I'm using Windows 10, Python 3.6 on Anaconda 3 and have faced the same issue.

I've had it work by doing the following in sequence:

  1. From Anaconda Terminal: pip install pydotplus
  2. From Anaconda Terminal: conda install pydotplus
  3. From Anaconda Terminal: pip install graphviz
  4. From Anaconda Terminal: conda install graphviz
  5. Went to Windows Environment Varialbes, PATH, and added the location of my dot.exe file under graphviz directory in Anaconda.

worked fine after that.

mazazino
  • 33
  • 4
2

I had faced same problem while trying to create decision tree through pydotplus and graphviz. And used the path variable method to resolve this issue.

Below are the exact steps I used:

  1. Although I already had graphviz through conda install command , I re-downloaded the latest package from below path. https://graphviz.gitlab.io/_pages/Download/Download_windows.html Downloaded : graphviz-2.38.zip (Stable Release)

  2. Copied the extracted folder under following path on C: Drive. C:\Program Files (x86)\

  3. Modified the system path variable and added following path to it. Path Variable : Control Panel > System and Security > System > Advance system Setting > Environment Variable > Path C:\Program Files (x86)\graphviz-2.38\release\bin;

  4. After adding above path to environment variable , restarted the system.

  5. It worked fine , and I was able to create Decision tree into png.

    enter image description here

1

I had the same issue with Windows 10.

First, I installed graphviz-2.38.0 with the following command without any problem...

install -c anaconda graphviz=2.38.0

Second, I installed pydotplus with the following command without any problem...

install -c conda-forge pydotplus

After that, when I got to my step to visualize my decision tree had the following issue with {InvocationException: GraphViz's executables not found}...

C:\Users\admin\Anaconda3\lib\site-packages\pydotplus\graphviz.py in create(self, prog, format)
   1958             if self.progs is None:
   1959                 raise InvocationException(
-> 1960                     'GraphViz\'s executables not found')
   1961 
   1962         if prog not in self.progs:

InvocationException: GraphViz's executables not found

In my case, all I had to do to fix it is to put the environment path of the graphviz executables in my user PATH environment variable and this fixed it. Just make sure it is the path where YOUR.exe files are located :)

C:\Users\admin\Anaconda3\pkgs\graphviz-2.38.0-4\Library\bin\graphviz
toonice
  • 2,211
  • 1
  • 13
  • 20
njgiv
  • 11
  • 1
1

Tried many ways and here is what really solved the problem - it worked for both windows 8.1/10 & python 3 .

1 . pip install graphviz

2 . the key action needed is to set the path variable by following steps below:

a. Control Panel > System and Security > System > Advanced System Settings > Environment Variables > Path > Edit b. add 'C:\Program Files (x86)\Graphviz2.38\bin'

James Cao
  • 11
  • 1
1

Try

import os

os.environ['PATH']=os.environ['PATH']+';'+os.environ['CONDA_PREFIX']+r"\Library\bin\graphviz"
Daniel Widdis
  • 8,424
  • 13
  • 41
  • 63
Sanya Jain
  • 11
  • 1
1

I solved this problem by first uninstalling all the installed versions of pydot, pydotplus and graphvis with

pip uninstall pydot 
pip uninstall pydotplus
pip uninstall graphviz

Then i re-installed them with :

conda install graphviz
conda install pydot
conda install pydotplus
Baya Lina
  • 457
  • 4
  • 11
1

On Windows

First, we need to install the library using pip:

pip install graphviz

Then, we can try running the following command (as suggested by other answers):

conda install graphviz

For me, however, this was causing an HTTP error enter image description here

After referring to the official documentation, I ended up choosing the path of installing graphviz via Chocolatey Package Manager.

Open your shell in Administrator mode, and run the following command:

choco install graphviz -y

Restart Kernel and the problem will be resolved.

Ayush Mandowara
  • 490
  • 5
  • 18
0

I had the same issue on Ubuntu(14.04) with Jupyter.

To solve it I've added the dot library to python sys.path

First: check if dot is installed,

Then: find his path whereis dot -> /local/notebook/miniconda2/envs/ik2/bin/dot

Finally in python script : sys.path.append("/local/notebook/miniconda2/envs/ik2/bin/dot")

nono
  • 2,262
  • 3
  • 23
  • 32
0

Please use pydotplus instead of pydot

  1. Find:C:\Users\zhangqianyuan\AppData\Local\Programs\Python\Python36\Lib\site-packages\pydotplus

  2. Open graphviz.py

  3. Find line 1925 - line 1972, find the function:

    def create(self, prog=None, format='ps'):
    
  4. In the function find:

    if prog not in self.progs:
        raise InvocationException(
            'GraphViz\'s executable "%s" not found' % prog)
    
    if not os.path.exists(self.progs[prog]) or \
            not os.path.isfile(self.progs[prog]):
        raise InvocationException(
            'GraphViz\'s executable "{}" is not'
            ' a file or doesn\'t exist'.format(self.progs[prog])
        )
    
  5. Between the two blocks add this(Your Graphviz's executable path):

      self.progs[prog] = "C:/Program Files (x86)/Graphviz2.38/bin/gvedit.exe"`
    
  6. After adding the result is:

    if prog not in self.progs:
        raise InvocationException(
            'GraphViz\'s executable "%s" not found' % prog)
    
    self.progs[prog] = "C:/Program Files (x86)/Graphviz2.38/bin/gvedit.exe"
    
    if not os.path.exists(self.progs[prog]) or \
            not os.path.isfile(self.progs[prog]):
        raise InvocationException(
            'GraphViz\'s executable "{}" is not'
            ' a file or doesn\'t exist'.format(self.progs[prog])
        )
    
  7. save the changed file then you can run it successfully.

  8. you'd better save it as bmp file because png file will not work. picture is here

albert
  • 8,285
  • 3
  • 19
  • 32
张乾元
  • 1
  • 2
  • Why twice the same answer https://stackoverflow.com/questions/18438997/why-is-pydot-unable-to-find-graphvizs-executables-in-windows-8/55507128#55507128 (i.e. double maintenance), better crosslink to other answer. – albert Apr 05 '19 at 08:46
0

I am not sure if this is an answer to THIS question, but this also seems to be the "how do I get graphviz to run on my setup?" thread. I also did not see python-graphviz mentioned anywhere.

As such: Ubuntu 16.04, conda Python 3.7, using Jupyter notebooks.

conda install -c anaconda graphviz
conda install -c conda-forge python-graphviz

The images would not render after trying only the first command; they did render after running the second.

I also installed pydot-plus, but did not see any change in behavior, performance, or image resolution.

Evan
  • 2,121
  • 14
  • 27
0

I was stuck for a very long time at this problem but after sometime I found a solution:

Matt Ke
  • 3,599
  • 12
  • 30
  • 49
sauravjoshi23
  • 837
  • 11
  • 9
0

For all those who are facing this issue in windows 10 even after trying the above mentiond steps, this worked for me - For Windows 10 users trying to debug this same error, launch CMD as administrator (important!) and run dot -c and then run dot -v
This fixed the issue for me

Marcus Richard
  • 33
  • 1
  • 2
  • 5
0

The simplest solution which worked for me (Windows 10, Jupyter Notebook) for this problem is to do the following:

  1. pip install graphviz
  2. restart jupyter
  3. Put the following code in notebook and execute:
import sys

sys.path.append('C:/Users/usrname/AppData/Local/Continuum/anaconda3/Library/bin/graphviz/')
DesiKeki
  • 656
  • 8
  • 9
0

This is the fresh solution I've used :)

I got the same problem, I'm using Anaconda and Jupyter Notebook.

What I did to solve this problem is NOT to install Graphiz.zip from the intenet!

I just did these steps:

  1. Create a new environment using >>conda create -n [env_name]
  2. install graphviz lib inside this new env: >> conda install graphviz
  3. I wrote this lines in the notebook cell and run it import os os.environ['PATH'] = os.environ['PATH']+';'+os.environ['CONDA_PREFIX']+r"\Library\bin\graphviz"

Finally, The image is appeared, I made a small party for this because it took 3 days from me :(

Weheid
  • 31
  • 3
0

For me (Windows 10 + Pycharm2020) this worked:

  • Added C:\Program Files\Graphviz\bin to PATH (path to Graphviz binaries)
  • Reboot - Maybe PyCharm restart would be enough
Vlade
  • 89
  • 1
  • 7
0

I just met the same issue. And here are my solutions.

1.) install the graphviz

make sure that you can find this folder INSTALL_LOCATION\"Graphviz2.38\bin"

2.) For the Dot object, add this code

dot.set_graphviz_executables( {'dot': r'C:\Program Files\Graphviz\bin\dot.exe'})

In graphviz.py, it does provide this function to manually set up the path for the execution file. Then, you should be able to run the code.

FYI: Here is the description from the set_graphviz_executables

    This method allows to manually specify the location of the GraphViz
    executables.

    The argument to this method should be a dictionary where the keys are
    as follows:

        {'dot': '', 'twopi': '', 'neato': '', 'circo': '', 'fdp': ''}

    and the values are the paths to the corresponding executable,
    including the name of the executable itself.
Patrick C
  • 21
  • 2
0

Full Steps to configure Graphviz for Anaconda - Jupiternotebook:

Download and install 'EXE installer for Windows 10' from : https://graphviz.org/download/

Environment Variable: Add C:\Program Files\Graphviz 2.44.1\bin to the user path

Environment Variable: Add C:\Program Files\Graphviz 2.44.1\bin\dot.exe to the system path

Check these steps after installing graphviz:

  1. pip install graphviz.
  2. pip install pydotplus
  3. conda install pydotplus
  4. Add path to environmental variables (C:\Users<username>\anaconda3\Library\bin\graphviz)
  5. Restart anaconda jupiter notebook kernel (if already running).