โ11-22-2022 12:49 AM
Hi everybody,
I created a simple bayesian model using the pymc library in Python. I would like to graphically represent my model using the pymc.model_to_graphviz(model=model) method.
However, it seems it does not work within a databrcks notebook, even after having installed the library "graphviz" in the cluster. In particular, the error that I get is the following:
ExecutableNotFound: failed to execute PosixPath('dot'), make sure the Graphviz executables are on your systems' PATH
Is there a way to overcome this problem?
โ11-28-2022 05:06 AM
I'm really sorry. It looks like graphviz needs to be installed from apt. I just totally thought the pypi package included the executable, but it looks like it doesn't (someone with a similar problem was here)
I believe `%sh apt install -y graphviz` should make pymc work (only on the driver node, so just for testing). When it comes to installing it to the cluster itself, I usually go to someone in the technology department to have them change whatever installation script for the cluster/startup. I believe it just does the above command but in an init script.
It's really throwing me for a loop that pypi didn't include an executable.
Let me know if this doesn't work. We'll get to the bottom of this.
โ11-24-2022 12:56 PM
A really basic question...do you have graphviz itself installed? Looks like pymc doesn't require it for installation (see for instance https://docs.pymc.io/en/v3/api/model_graph.html)
%pip install graphviz
does it say that it's already installed? I had a similar issue in cython with using libgsl (I thought the package requiring it had installed it, but no)
edit: if anyone is coming here from google in the future. the solution above in itself isn't complete. pip only installs the python bindings for the graphviz executables (as detailed below). you'll still need to install graphviz either through apt or conda.
edit 2: if anyone is here from google in the future, your frustration in solving this problem is entirely valid and so are you ๐ ... hopefully this solution works for your problem too.
โ11-28-2022 02:27 AM
Yes, I have installed graphviz library directly to the cluster I use.
โ11-28-2022 05:06 AM
I'm really sorry. It looks like graphviz needs to be installed from apt. I just totally thought the pypi package included the executable, but it looks like it doesn't (someone with a similar problem was here)
I believe `%sh apt install -y graphviz` should make pymc work (only on the driver node, so just for testing). When it comes to installing it to the cluster itself, I usually go to someone in the technology department to have them change whatever installation script for the cluster/startup. I believe it just does the above command but in an init script.
It's really throwing me for a loop that pypi didn't include an executable.
Let me know if this doesn't work. We'll get to the bottom of this.
โ11-28-2022 05:36 AM
Thank you very much! by using:
%sh apt install -y graphviz
directly on the notebook cell it does work. You've been really helpful.
Now when I run:
pymc.model_to_graphviz(model=model)
I get:
<graphviz.graphs.Digraph at 0x7f7fb2634d90>
I also tried to use the "render" method:
pm.model_to_graphviz(model=hierarchical).render()
But the output is just the string:
'.gv.pdf'
Do you know if it is possible to render the graph inside the notebook? Or otherwise where to find the graph?
Once again, thank you very much
โ11-28-2022 07:59 AM
preface that I'm not exactly in love with the solution below. does this work?
graph = pm.model_to_graphviz(model=hierarchical)
displayHTML(graph.pipe(format="svg").decode("utf-8"))
also the reason it gives you that .pdf type thing is because by default it renders it to a pdf, and you set the filename using the filename parameter. you can do different formats (pdf,png,svg,...)
โ11-28-2022 08:23 AM
Yes it works!
Thank you very much! I tried that solution but without the "format" parameter in the .pipe method and it didn't work.
Thank again for your help.
โ12-02-2022 04:07 AM
%sh apt install -y graphviz
Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโt want to miss the chance to attend and share knowledge.
If there isnโt a group near you, start one and help create a community that brings people together.
Request a New Group