11

So I've had Python 3.6 on my Windows 10 computer for a while now, and today I just downloaded and installed the graphviz 0.8.2 (https://pypi.python.org/pypi/graphviz) package via the admin commandline with:

pip3 install graphviz

It was only after this point that I downloaded the Graphviz 2.38 MSI installer file and installed the program at:

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

So then I tried to run this simple Python program:

from graphviz import Digraph

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.render('round-table.gv', view=True)

But unfortunately, I received the following error when I try to run my Python program from commandline:

Traceback (most recent call last):
  File "C:\Program Files\Python36\lib\site-packages\graphviz\backend.py", line 124, in render
    subprocess.check_call(args, startupinfo=STARTUPINFO, stderr=stderr)
  File "C:\Program Files\Python36\lib\subprocess.py", line 286, in check_call
    retcode = call(*popenargs, **kwargs)
  File "C:\Program Files\Python36\lib\subprocess.py", line 267, in call
    with Popen(*popenargs, **kwargs) as p:
  File "C:\Program Files\Python36\lib\subprocess.py", line 709, in __init__
    restore_signals, start_new_session)
  File "C:\Program Files\Python36\lib\subprocess.py", line 997, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\foldername\testing.py", line 11, in <module>
    dot.render('round-table.gv', view=True)
  File "C:\Program Files\Python36\lib\site-packages\graphviz\files.py", line 176, in render
    rendered = backend.render(self._engine, self._format, filepath)
  File "C:\Program Files\Python36\lib\site-packages\graphviz\backend.py", line 127, in render
    raise ExecutableNotFound(args)
graphviz.backend.ExecutableNotFound: failed to execute ['dot', '-Tpdf', '-O', 'round-table.gv'], make sure the Graphviz executables are on your systems' PATH

Notice how what I've asked seems VERY similar to this question asked here: "RuntimeError: Make sure the Graphviz executables are on your system's path" after installing Graphviz 2.38

But for some reason, adding those paths (suggested in the solutions at the link above) to the system variables isn't working, and I don't know why! I tried restarting the computer after adding the paths as well, still to no success. See the image below:

enter image description here

Although the other suggested solution, which was to add these few lines in front of my Python code, did work:

import os
os.environ["PATH"] += os.pathsep + 'C:/Program Files (x86)/Graphviz2.38/bin/'

But here's the issue: I don't understand why adding to the environment variables didn't work, and this is my primary concern. So my question is this: why did adding those lines of code in front of the Python script work but changing the environment variables didn't? What do I need to do to get my script to run without adding those lines of code in front?

ereHsaWyhsipS
  • 427
  • 1
  • 5
  • 12

1 Answers1

8

Can you please post the output you get when you type SET in a cmd window after setting the PATH environment variable?

Does it contain C:/Program Files (x86)/Graphviz2.38/bin/ ?

A cmd window must be restarted before updated environment variables become effective!

Michael P
  • 328
  • 3
  • 7
  • It does contain `Graphviz=C:\Program Files (x86)\Graphviz2.38\bin`. And I have restarted the command window plenty of times, still to no avail. – ereHsaWyhsipS Mar 25 '18 at 02:31
  • That looks wrong. It should be only the path, without `Graphviz=` Something like: `PATH=C:\WINDOWS;C:\Program Files...;C:\Program Files (x86)\Graphviz2.38\bin` – Michael P Mar 25 '18 at 02:36
  • If you look at my image in my original post, I had set the variable name itself to be "Graphviz." Are you saying that it should have no name at all? I don't quite understand what this means I need to do. – ereHsaWyhsipS Mar 25 '18 at 02:39
  • 1
    it says `make sure the Graphviz executables are on your systems' PATH` Thus, set your PATH, like so `set PATH=%PATH%;C:\Program Files (x86)\Graphviz2.38\bin` See also: https://stackoverflow.com/questions/9546324/adding-directory-to-path-environment-variable-in-windows – Michael P Mar 25 '18 at 02:42
  • 1
    Wow, I'm an idiot. Okay, I finally figured it out. This is what I had to do: I had to add it to the already existing path environment variable, not create a new variable altogether. Thanks for helping me finally figure this out. – ereHsaWyhsipS Mar 25 '18 at 07:20