brussell_1900
brussell_1900

Reputation: 121

Where do I add Graphviz's Executable on a Mac

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.

Upvotes: 5

Views: 38320

Answers (3)

SFIDK
SFIDK

Reputation: 31

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!

Upvotes: 3

J_H
J_H

Reputation: 20568

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.

Upvotes: 9

brussell_1900
brussell_1900

Reputation: 121

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.

Upvotes: 4

Related Questions