3

I'm trying to use Graphviz but am getting the error message:

graphviz.backend.ExecutableNotFound: failed to execute ['dot', '-Tpdf', '-O', 'test-output/aoc.gv.pdf'], make sure the Graphviz executables are on your systems' PATH

The code I am running is cut and pasted from the documentation:

from graphviz import Digraph, Graph
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')
dot.render('test-output/aoc.gv.pdf')

The file will output to the correct folder and the file is there and it has 170 bytes but it will not open. I have tried other extensions such as just 'gv' and they do not work either. I'm using the latest version of Graphviz which is 0.10.1 and I have tried opening this file on a PC and it does not work on PC either (I have a Mac). This problem is similar to

Graphviz's executables are not found (Python 3.4)

and

Why is pydot unable to find GraphViz's executables in Windows 8?

However, there are major stumbling blocks to my understanding these posts. Number one, I have very little understanding of how Python is executed on a computer, so I really don't even know what an environment variable is. Second, when they refer to computer's PATH I can only assume that they're talking about the directory of the file which is executing the Graphviz module, but I'm not sure about that. So I've added this line of code:

import sys
str1 = "/library/frameworks/python.framework/versions/3.6/lib/python3.6/site-packages/graphviz/"
sys.path.append(str1)

But that is not working. Third, if I were to implement this step:

Add this string to the end of your Variable value list (including semicolon): ;C:\Program Files (x86)\Graphviz2.34\bin

Then I would have to translate that into its Mac counterpart and I'm not able to. Any help would be appreciated.

brussell_1900
  • 51
  • 1
  • 1
  • 8
  • 2
    Have you installed the actual Graphviz (not a python package, but the actual program)? e.g. `brew install graphviz`? – Dany Mar 03 '19 at 12:22
  • Read http://www.linfo.org/path_env_var.html to understand how PATH works. `brew` usually installs everything under `/usr/local/bin`. – tk421 Mar 03 '19 at 15:08
  • Where does Homebrew install Graphviz? I've yet to find one site that includes this critical information! It's not in /Applications. – Oscar Feb 25 '21 at 21:44

3 Answers3

5

The diagnostic is saying that dot is not in your $PATH, it does not appear in any of the directories mentioned by that env var. You want to get to a point where trying the following command reports some version number:

$ dot -V
dot - graphviz version 2.40.1 (20161225.0304)
$
$ which dot
/usr/local/bin/dot
$
$ echo $PATH | tr : ' ' | fmt -w1 | grep local
/usr/local/bin

If you are not yet using Brew, you should. It's the easiest way to get this and many other programs onto your Mac. Visit https://brew.sh/ and follow the instructions. Then type:

$ brew install graphviz
...
$ /usr/local/bin/dot -V

That should work just fine. If dot -V says "not found" then simply append the proper directory to your PATH:

$ export PATH="${PATH}:/usr/local/bin"

If your bash shell can run it, then your python program should be able to, as well.

J_H
  • 17,926
  • 4
  • 24
  • 44
  • Thanks for helping me out. I already had homebrew installed but that doesn't matter because I don't understand how it works anyway. When I put in the command `/usr/local/bin/dot -V` I got the error message: `/usr/local/bin/dot: No such file or directory`. When I input `export PATH="${PATH}:/usr/local/bin"` I did not get an error message but the program will not work. I tried substituting PATH for the path that the module is in which is: `/Users/me/PycharmProjects/inference_engine2/inference2/proofs/other/` but that gave the message: `bad substitution` – brussell_1900 Mar 03 '19 at 18:53
  • It sounds like `dot` is not installed on your Mac. Use `$ brew install graphviz` to install it in the default location of /usr/local/bin. – J_H Mar 03 '19 at 18:57
  • I put in `brew install graphviz` and everything worked fine. I did get this message `Error: The following directories are not writable by your user: /usr/local/share/man/man3 /usr/local/share/man/man5 /usr/local/share/man/man7` But I'm not sure that is relevant. – brussell_1900 Mar 03 '19 at 18:59
  • Also when I write: `echo $PATH` I get: `/Library/Frameworks/Python.framework/Versions/3.6/bin:/usr/local/bin/dot` – brussell_1900 Mar 03 '19 at 19:03
  • In short, at the documentation it says: "Make sure that the directory containing the dot executable is on your systems’ path." I just can't figure out what that means. – brussell_1900 Mar 03 '19 at 19:06
  • Over at this site: https://coolestguidesontheplanet.com/add-shell-path-osx/ I found this guy who is adding mysql with the following: export PATH="/usr/local/mysql/bin:$PATH". So I tried something analogous like: `export PATH="/usr/local/graphviz/bin:$PATH" export PATH="/usr/local/dot/bin:$PATH"` – brussell_1900 Mar 03 '19 at 19:15
  • Ok, here is something on my bash_profile. It has: `PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"`. I need to find some way to alter that string so that graphviz will work. Any ideas? – brussell_1900 Mar 03 '19 at 21:03
  • ```brew install graphviz``` this help me! Thanks ;) – Darkhan Apr 22 '20 at 14:32
2

I tried these commands to help me locate the DOT file path on my mac. It was not: "/usr/local/bin/dot" on my system.

dot -V

dot - graphviz version 2.49.2

which dot

/opt/homebrew/bin/dot

I had installed Graphviz, but I was still running into trouble finding the right path. I am using Protege, and I had to modify the path for OwlViz since it was displaying the entire hierarchy at (0,0). I copied the path that I got by running the which dot command to the OWLViz tab on the preference dialog, and restarted protege and it worked perfectly! Good luck!

ilalmi
  • 21
  • 3
0

Problem solved. It took me a while to figure out that I had to download some non-pythonic software before I could get the pythonic software to work.

brew install graphviz

Was step 1 and I had done that before but I was getting an error message. It told me to change ownership of some files so I did that. Then tried

brew install graphviz

again and that did the trick.

brussell_1900
  • 51
  • 1
  • 1
  • 8