Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dtreeviz: from graphviz.backend cannot import name 'run'

dtreeviz library, ImportError: cannot import name 'run'

I tried to follow this instruction on Github to install and import the dtreeviz library. When I run the where dot and dot -V command both seem to work fine as you can see here Lines in Windows Terminal. However when I try to import dtreeviz in Python (Anaconda, version 3.6.5) I get the following error:

from dtreeviz.trees import *
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-2-fd764fe550c7> in <module>()
      1 from sklearn import tree
----> 2 from dtreeviz.trees import *

C:\Users\marcb\Anaconda3\lib\site-packages\dtreeviz\trees.py in <module>()
      6 from pathlib import Path
      7 from sklearn import tree
----> 8 from graphviz.backend import run, view
      9 import matplotlib.pyplot as plt
     10 from dtreeviz.shadow import *

ImportError: cannot import name 'run'

I hope that someone can help me as I want to use this library to visualize single trees in Python and this library offers much more features than the original graphviz package.

Note: This is my first post on Stackoverflow, so feedback on this is also welcome.

like image 539
Naron Avatar asked Mar 27 '19 10:03

Naron


1 Answers

I don't know if you are still looking for an awser, but i had exactly the same problem and fixed it this way:
In ~/.local/lib/python3.8/site-packages/dtreeviz/trees.py' i replaced the line
79: execute(' '.join(cmd), capture_output=True, check=True, quiet=False)
by
79: os.system(' '.join(cmd)).

like image 199
Basile Lamotte Avatar answered Nov 09 '22 03:11

Basile Lamotte