0

Question: How to correctly execute 'dot' from Graphviz in Spyder (Anaconda) in macOS?

Context: I know this topic has been already addressed in other posts:

But I have tried all the recommendations on these posts and I still get the errors:

Exception: “dot” not found in path in python on mac

FileNotFoundError: [Errno 2] No such file or directory: 'dot'

ExecutableNotFound: failed to execute ['dot', '-Kdot', '-Tpdf', '-O', 'FileName'], make sure the Graphviz executables are on your systems' PATH

I have already installed Graphviz, and as you can see below, dot is working:

enter image description here

Above can be seenn that by typing:

dot -V

It returns the version I have installed. As well as when typing:

which dot

It returns the location of the file (i.e., /usr/local/bin). I have tried several things with this path.

  1. Add it to the path in Spyder:

enter image description here

  1. I added to the main system PATH:

enter image description here

  1. And I even run a script in Python trying to add the path from the code (I have tried it with and without 'dot' at the end of the path):

enter image description here

None of the above solutions worked for me. If anyone could give me some insights to solve this problem, I would really appreciate it.

As an example, you can try the code below, which is the one that gives me the error (source):

import graphviz

dot = graphviz.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('FileName', view=True)
lisandrojim
  • 509
  • 5
  • 18

1 Answers1

0

Apart from having in the main system path the location of the ".dot" executable and added it to the PATH from Spyder in PYTHONPATH manager, I tried several other things, I will summarize the steps that worked for me. I hope this works also for you.

  • Step 1: I downloaded Anaconda from the official site.

  • Step 2: The version I installed was 1.10.0. This version had already pre-installed Spyder 4.1.5

  • Step 3: I tried to run the example I gave in the description above, but appeared the same errors. I tried to install Graphviz using the command (from the Spyder console):

    conda install graphiz

  • Note: When I used the above command, it took forever and appeared some problems with the environment with a message saying "solving environment ..." Then I decided to stop it (CTRL+C), and continue with Step 4.

  • Step 4: I updated Anaconda and Spyder using respectively the following commands:

    conda update anaconda

    conda update spyder

  • Note: I checked the Spyder version, and it was already 4.2.1 (before it was 4.1.5)

  • Step 5: Now, I opened Spyder, and typed again the command:

    conda install graphiz

  • Note: This time, at the beginning appeared a few warning messages, but after a minute it successfully installed.

  • Step 6: I re-started the kernel, and run again the example, and this time it worked!!

Below you can see that Graphviz appears in the Anaconda environment (which before it didn't):

enter image description here

In the end, I executed this example:

import graphviz

dot = graphviz.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('FileName', view=True)

And I obtained:

enter image description here

lisandrojim
  • 509
  • 5
  • 18