Failed to execute windowspath(‘dot’), make sure the graphviz executables are on your systems’ path

Let’s talk about an error that surfaces up pretty often when working with graphs in Python – the “Failed to execute windowspath(‘dot’), make sure the Graphviz executables are on your systems’ path” This error message can be pretty frightening, especially for beginners. But don’t worry, we’re here to discuss why this error occurs and how to fix it.

What is the “Failed to Execute windowspath(‘dot’)”?

The error, “Failed to execute windowspath(‘dot’), make sure the Graphviz executables are on your systems’ path”, generally pops up when you’re trying to use the Graphviz library in Python but the required Graphviz software is not installed in your system, and hence Python is unable to locate its executable file.

Additionally, this error can also arise if the PATH environment variable has not been set correctly.

What causes the “Failed to Execute windowspath(‘dot’)” error?

The main cause of this error is the absence of Graphviz software on your machine, or the Graphviz binaries not being on your system’s path. Basically, Python is unable to find the ‘dot’ executable. For Python to call external software like Graphviz, the executable files of these software programs need to be in a location that Python can access.

Code Example

You may come across the “Failed to Execute windowspath(‘dot’)” error when you’re trying to run code that looks something like this:

from graphviz import Source

dot_code = """
   digraph G {
       Hello -> World;
   }
"""

Source(dot_code)

Output

ExecutableNotFound: failed to execute ['dot', '-Tsvg'], make sure the Graphviz executables are on your systems' path

How to resolve the “Failed to Execute windowspath(‘dot’)” error?

Now, let’s discuss how we can resolve this error.

  • Install the Graphviz package in your system: This is foundational. You need to install the Graphviz package in your system, not just the python package. The specific command would depend on your operating system. For Ubuntu, use sudo apt-get install graphviz.
  • For MacOS: You can use this simple command to install Graphviz: brew install graphviz. I’d suggest against using ‘conda install graphviz’ to install the Graphviz binary as it may cause the “Graphviz not executable” error. A better approach would be to use homebrew to install Graphviz binary, and then install python-graphviz. Homebrew will guarantee the binary is executable.
  • For Windows: If you are a Windows user, you can try and add these 2 lines at the start of your code, replacing ‘D:/Program Files (x86)/Graphviz2.38/bin/’ with the location where your bin file is located.
import os
os.environ["PATH"] += os.pathsep + 'D:/Program Files (x86)/Graphviz2.38/bin/'
  • Install Windows package and Python Graphviz package: You can also try installing the windows package from: https://graphviz.gitlab.io/_pages/Download/Download_windows.html and then installing python graphviz package. Post which, add C:\Program Files (x86)\Graphviz2.38\bin to User path and C:\Program Files (x86)\Graphviz2.38\bin\dot.exe to System Path.
  • For conda users: If you have used conda to install Graphviz, the executables sit on a different path from your conda directory. Hence, it’s better to use conda install python-graphviz instead of pip install graphviz.

Conclusion

I hope this post helps you understand the error “Failed to Execute windowspath(‘dot’)” and how to resolve it. Remember, always make sure to have the Graphviz binaries on your system’s path before running any Graphviz scripts. Don’t forget to triple-check the paths if you’re facing consistent issues. Happy coding!

References

  1. Graphviz

Follow us at PythonClear to learn more about solutions to general errors one may encounter while programming in Python.

Leave a Comment