parrt / dtreeviz

A python library for decision tree visualization and model interpretation.
MIT License
2.94k stars 331 forks source link

Installation on computer without frontend? - no method opening "image/svg+xml" #250

Closed kliegr closed 1 year ago

kliegr commented 1 year ago

I struggle correctly configuring dtreeviz on Ubuntu 20.04.5 LTS. A possible reason is that it is run on a server machine with no GUI frontend via JupyterHub.

I installed with

pip install dtreeviz

as this did not found the "dot" folder, I also installed

sudo apt-get install graphviz

Now with the hello world Iris example I get:

Error: no "view" mailcap rules found for type "image/svg+xml"
/usr/bin/xdg-open: 869: www-browser: not found
/usr/bin/xdg-open: 869: links2: not found
/usr/bin/xdg-open: 869: elinks: not found
/usr/bin/xdg-open: 869: links: not found
/usr/bin/xdg-open: 869: lynx: not found
/usr/bin/xdg-open: 869: w3m: not found
xdg-open: no method available for opening '/tmp/DTreeViz_1168766.svg'

On another similar machine (same OS, also no UI), I also get

findfont: Font family 'Arial' not found.
parrt commented 1 year ago

not sure but maybe it has trouble viewing svg. If headless, this could be a problem with what's installed.

kliegr commented 1 year ago

Thanks for the pointers. I resolved this as follows but partly it is a workaround. The first error (xdg-open: no method available for opening) was resolved by installing a web browser on the server:

sudo apt-get install w3m

This made the package render the svg and save it, but not display it. The probable reason is persisting error "Error: no "view" mailcap rules found for type "image/svg+xml". For this, the workaround is to load and display the saved file instead of calling `show' from dtreeviz.

from IPython.display import SVG, display
display(SVG('iris.svg'))
parrt commented 1 year ago

So it sounds like this is more or less resolved by making sure that the server, despite being headless, still has the required libraries in functionality. Thanks for posting as others will find this very useful