32

I'm having trouble running Python's pydot on Windows 7.

I installed pydot with: conda install -c rmg pydot=1.2.2

I have graphviz installed under ../Program Files (x86)/Graphviz2.38/

When I run the following script I get an error saying

"dot.exe" not found in path
import pydot
graph = pydot.Dot(graph_type='digraph')
node_a = pydot.Node("Node A", style="filled", fillcolor="red")
node_b = pydot.Node("Node B", style="filled", fillcolor="green")
node_c = pydot.Node("Node C", style="filled", fillcolor="#0000ff")
node_d = pydot.Node("Node D", style="filled", fillcolor="#976856")
graph.add_node(node_a)
graph.add_node(node_b)
graph.add_node(node_c)
graph.add_node(node_d)
graph.add_edge(pydot.Edge(node_a, node_b))
graph.add_edge(pydot.Edge(node_b, node_c))
graph.add_edge(pydot.Edge(node_c, node_d))
graph.add_edge(pydot.Edge(node_d, node_a, label="and back we go again", labelfontcolor="#009933", fontsize="10.0", color="blue"))
graph.write_png('example2_graph.png')

Exception: "dot.exe" not found in path.

I have tried this solution: Permanently adding a file path to sys.path in Python, by adding the my-paths.pth file with a line pointing to ../Graphiv2.38/bin/ where the dot.exe file is located. But I still get the error.

What else can I try?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Dubraven
  • 921
  • 2
  • 9
  • 16
  • You need to add the absolute path to dot.exe in your enviorment variable %PATH% and not the relative path. If this doesn't work, update your post with a screenshoot of your %PATH% dump. Very important, Windows pathes only works with backslashes. – Turrican Nov 16 '16 at 12:45

9 Answers9

57

I followed the instructions given in this blog.

Then I installed graphviz from here and added C:\Program Files (x86)\Graphviz2.38\bin to PATH.

Next I did:

conda install pydot-ng 

And finally in my notebook I added the two lines below.

import os
os.environ["PATH"] += os.pathsep + 'C:/Program Files (x86)/Graphviz2.38/bin/'
Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
Ernest S Kirubakaran
  • 1,524
  • 12
  • 16
  • 2
    This solution worked for me too, only change that the download now can be found on: http://www.graphviz.org/download/ – Бојан Матовски Mar 23 '18 at 22:05
  • 4
    Although I added manually Graphviz to PATH, only adding the two lines solved the problem for me. – Guy s May 08 '18 at 14:23
  • How did you download graphviz from http://www.graphviz.org/download/? I'm having a hard time – Chaine Jul 14 '18 at 06:54
  • 1
    might want to note that you might not need to conda install pydot-ng. That rolled back my version of python which took some work to undo. the import os and os.environ worked like a charm – Supamee Aug 14 '18 at 15:15
  • 1
    Please don't ignore his last point: import os and os.environ["PATH"] += os.pathsep + 'C:/Program Files (x86)/Graphviz2.38/bin/' – DK250 Oct 19 '18 at 04:34
  • 1
    You can install the binaries with `conda install graphviz` and then put those in your path instead of `Program Files`. – endolith Nov 30 '18 at 20:54
  • 1
    graphviz 2.44.1 on windows was not working. i uninstalled 2.44.1 and installed 2.38 and it worked – user190245 Sep 11 '20 at 17:23
13

Type conda install pydot graphviz in cmd, and then add the executables location directory C:\Anaconda3\pkgs\graphviz-2.38-hfd603c8_2\Library\bin\graphviz to your system path variable. That works!

jmir
  • 399
  • 2
  • 9
  • 1
    It works! It seems there is no need to change the system path to use ``graphviz`` and ``pydot`` in a ``conda`` environment and the associated python. – SaltedFishLZ Feb 18 '21 at 19:39
  • This method solved this issue for me as well—no need to add Envir Vars, as @SaltedFishLZ mentions. – MrPmosh Jun 07 '22 at 00:01
11

Don't use the following command if you are on Python 3:

conda install pydot-ng 

This will take your installation to Python 2.7

Use instead

conda install graphviz
3

Other solutions didn't work for me, and I figured out pydot tried to run a hardcoded dot.bat so I just created dot.bat wrapper nearby dot.exe and it worked:

@echo off
dot %*
Rabash
  • 4,529
  • 3
  • 19
  • 18
2

Using django-extensions to generate the model graph for your Django application, I did this and it worked:

pip install django-extensions
pip install pyparsing
pip install graphviz
pip install pydot
conda install graphviz

Add django-extensions to you INSTALLED_APPS and then add C:\Program Files\Anaconda3\pkgs\graphviz-2.38.0-4\Library\bin\graphviz to my system path variable. Then finally and normally:

python manage.py graph_models -a -g -o pic.png
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Gret
  • 325
  • 2
  • 6
2

I was having trouble with this and found out that if you're using the Visual Studio Code integrated command line then you should make sure to restart Visual Studio Code (you might need to only restart the command line) otherwise the PATH changes won't take place...

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
ToxicGLaDOS
  • 441
  • 5
  • 16
  • 1
    I think it applies to any editor. With the PyCharm too, you need to restart it. – smm Oct 12 '18 at 21:02
1

In this kind of cases, when resources are not found by programs on your system, follow these quick steps:

  • Run a simple command prompt, type and execute the needed command (can be 'dot.exe')
  • If yes, your system is nicely configured and perhaps due to a hard configured way in your code, executables are not found (need a specific location for files to be found for instance: program check for C:\Program Files\Anaconda3\pkgs\graphviz and you put binaries in C:\Program Files\graphviz).
  • If no, you need to add it manually. In environment variable add the directory that contains the binaries (for instance 'my_location\graphviz\bin'). If you need it for whole users of the computer, put it in the system 'Path' (need to disconnect the users accounts to be considered), else in the user 'Path' (need to reopen the needed program). Then check it by re-opening a command prompt and typing the command.

If it's not working... you mistyped something =)

Some advices: Rapid Environment Editor is pretty cool for configuring windows environment variables ;)

Have a nice day!

Romain Cendre
  • 309
  • 2
  • 12
1

On Ubuntu 18.04 installing the binaries with sudo apt-get install graphviz led to dot being placed under /usr/bin/dot (it might go to /usr/local/bin/dot per their installation guide). After doing:

pip3 install pydot-ng

and adding the following lines (similar to @Ernest's answer in Linux) to the script it worked:

import os
os.environ["PATH"] += os.pathsep + "/usr/bin/dot"
Farzad Vertigo
  • 2,458
  • 1
  • 29
  • 32
0

I've had some very bad experiences with conda, so avoid the mess it causes at all cost.

Fortunately every answer here is using conda unnecessarily. You can simply install this package with pip install pydot then after adding Graphviz to your path as described in the accepted answer, this error is resolved. (Windows)

Recessive
  • 1,780
  • 2
  • 14
  • 37