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.
in Anaconda install
This will fix your problem
如果您的操作系统是Ubuntu,我建议您尝试以下命令:
sudo apt-get install -y graphviz libgraphviz-dev
As @grrr answered above, here is the code:
conda install -c anaconda python-graphviz
conda install -c anaconda pydot
I installed the grphviz package using conda. However, I kept getting "module not found error" even after restart kernel multiple times.
I even tried installing "PyDot", as suggested on this page, however, it didn't really help.
Finally, I installing the package using
pip install graphviz
worked and now I can import it without errors.
I know the question has already been answered, but for future readers, I came here with the same jupyter notebook issue; after installing python-graphviz and pydot I still had the same issue. Here's what worked for me: Make sure that the python version of your terminal matches that of the jupyter notebook, so run this both in python in your terminal and then in your juypter notebook. If you are using a conda environment, load the environment before checking the python version.
import sys
print(sys.version)
If they do not match, ie python 3.6.x vs python 3.7.x then give your jupyter notebook the ability to find the version of python you want.
conda install nb_conda_kernels
conda install ipykernel
and if you are using a conda environment,
python -m ipykernel install --user --name myenv--display-name "Python (myenv)"
where myenv
is the name of your environment. Then go into your jupyter notebook, and in kernel -> change kernel, select the correct version of python. Fixed the issue!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.