parrt/dtreeviz

Google Cloud Function support/how-to?

Opened this issue · 0 comments

I would like to use this library in a Google Cloud Function. A couple of issues:

  1. Is it possible to save the SVG to a BytesIO object, I tried but was unsuccessful. We don't have the option for local storage.
  2. graphviz.backend.execute.ExecutableNotFound: failed to execute 'dot', make sure the Graphviz executables are on your systems' PATH - Is there a way around this? ( I get similar error from Mac install).
    I noted it does work on Google Colab.

I suspect it's the sys.path between system and environment.

From GCF shell:
python -c import subprocess; proc = subprocess.Popen(['dot','-V'])
dot - graphviz version 2.43.0 (0)

From GCF Python 3.11:
proc = subprocess.Popen(['dot','-V'])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/layers/google.python.runtime/python/lib/python3.11/subprocess.py", line 1026, in init
self._execute_child(args, executable, preexec_fn, close_fds,
File "/layers/google.python.runtime/python/lib/python3.11/subprocess.py", line 1955, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'dot'

Local MacBook Pro (almost the same issue):

$ dot -V
dot - graphviz version 2.43.0 (0)

$ which dot
/usr/local/bin/dot

(Okay)
$ python3 -c "import subprocess; proc = subprocess.Popen(['dot','-V'])"
$ dot - graphviz version 12.0.0 (20240704.0754)

(Not okay)
From JupyterLab:
import subprocess
proc = subprocess.Popen(['dot','-V'])
FileNotFoundError: [Errno 2] No such file or directory: 'dot'

From Terminal
$ echo $PATH
...
/usr/local/bin
...

From JupyterLab:
import sys
sys.path
['/Users/gavinbeattie/Desktop/python-studio',
'/Users/gavinbeattie/anaconda3/lib/python311.zip',
'/Users/gavinbeattie/anaconda3/lib/python3.11',
'/Users/gavinbeattie/anaconda3/lib/python3.11/lib-dynload',
'',
'/Users/gavinbeattie/.local/lib/python3.11/site-packages',
'/Users/gavinbeattie/anaconda3/lib/python3.11/site-packages',
'/Users/gavinbeattie/anaconda3/lib/python3.11/site-packages/aeosa']

And
import os
print( os.getenv('PATH') )
/Users/gavinbeattie/anaconda3/bin
/Users/gavinbeattie/anaconda3/condabin
/usr/bin
/bin
/usr/sbin
/sbin

Where and how do I change/add /usr/local/bin/dot to enable it to work in Google Cloud Funtions/JupyterLab please?