Search code examples
pythondatabricksgraphvizdecision-tree

Error when trying yo convert a plot for a decision tree from .dot to .png


My problem is the following:

When running this piece of code:

(graph,) = graph_from_dot_file('tree.dot')
graph.write_png('/mnt/tree1.png')

I get this error, regarding the second line of the code above:

FileNotFoundError: [Errno 2] "dot" not found in path.

I've seen some posts regarding similar questions, but none of them talked specifically about databricks. I have no idea of how to find where the package is installed and to add it to my PATH environment variable


Solution

  • The dot program is the part of the graphviz package that could be installed onto the machine using package manager. Just execute:

    %sh 
    apt-get -y install graphviz
    

    The %sh allows you to execute shell commands from the notebook. Take into account that they are executed only on the driver node, not on all nodes of the cluster. If you'll need to install something like this on all nodes, or to do that automatically on cluster start, you can use cluster init scripts.