Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No module named 'graphviz' in Jupyter Notebook

I tried to draw a decision tree in Jupyter Notebook this way.

mglearn.plots.plot_animal_tree()

But I didn't make it in the right way and got the following error message.

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-65-45733bae690a> in <module>()
      1 
----> 2 mglearn.plots.plot_animal_tree()

~\Desktop\introduction_to_ml_with_python\mglearn\plot_animal_tree.py in plot_animal_tree(ax)
      4 
      5 def plot_animal_tree(ax=None):
----> 6     import graphviz
      7     if ax is None:
      8         ax = plt.gca()

ModuleNotFoundError: No module named 'graphviz

So I downloaded Graphviz Windows Packages and installed it.

And I added the PATH installed path(C:\Program Files (x86)\Graphviz2.38\bin) to USER PATH and (C:\Program Files (x86)\Graphviz2.38\bin\dot.exe) to SYSTEM PATH.

And restarted my PC. But it didnt work. I still can't get it working.

So I searched over the internet and got another solution that, I can add the PATH in my code like this.

import os
os.environ["PATH"] += os.pathsep + 'C:/Program Files (x86)/Graphviz2.38/bin'

But it didn't work. So I do not know how to figure it out now.

I use the Python3.6 integrated into Anacode3.

And I ALSO tried installing graphviz via PIP like this.

pip install graphviz

BUT it still doesn't work.

Hope someone can help me, sincerely.

like image 985
Bowen Peng Avatar asked Sep 29 '18 08:09

Bowen Peng


People also ask

How do I know if Python is installed on graphviz?

Run "dot -V" from the command prompt. If GraphViz is installed and configured you'll get it's version.

What is graphviz in Python?

Graphviz is an open-source graph visualisation software. The graphviz package, which works under Python 3.7+ in Python, provides a pure-Python interface to this software. This package allows to create both undirected and directed graphs using the DOT language.


3 Answers

in Anaconda install

  • python-graphviz
  • pydot

This will fix your problem

like image 117
grrr Avatar answered Oct 18 '22 15:10

grrr


As @grrr answered above, here is the code:

conda install -c anaconda python-graphviz

conda install -c anaconda pydot
like image 44
Mai Hai Avatar answered Oct 18 '22 13:10

Mai Hai


In case if your operation system is Ubuntu I recommend to try command:

sudo apt-get install -y graphviz libgraphviz-dev
like image 5
Lana-na Avatar answered Oct 18 '22 14:10

Lana-na