0

I am currently using spyder 3.6 on Windows 8 OS and whenever I run this code it shows an error

File "", line 12, in import pydotplus

ModuleNotFoundError: No module named 'pydotplus'

Here is the code

import pydotplus 
dot_data = tree.export_graphviz(clf, out_file=None) 

graph = pydotplus.graph_from_dot_data(dot_data) 

graph.write_pdf("iris.pdf") 

from IPython.display import Image  
dot_data = tree.export_graphviz(clf, out_file=None,feature_names=iris.feature_names,  

class_names=iris.target_names,  

filled=True, rounded=True,  

special_characters=True)

graph = pydotplus.graph_from_dot_data(dot_data)  

Image(graph.create_png())
Saradamani
  • 180
  • 1
  • 3
  • 18
  • Well, you should _install_ that module first. – ForceBru Mar 22 '17 at 15:31
  • But Can you please tell me how to install it? I do not find documentations on the web.Can you please help? – Saradamani Mar 22 '17 at 15:35
  • have you tried searching on Stack Overflow itself? I managed to find this: http://stackoverflow.com/questions/10729116/adding-a-module-specifically-pymorph-to-spyder-python-ide – ForceBru Mar 22 '17 at 15:45
  • I have installed it thanks for help. But I can't install GraphViz.StackOverflow says pip install GraphViz.But it is showing errors on my Windows PowerShell saying 'Cannot import name 'main''. – Saradamani Mar 22 '17 at 16:09
  • what's the exact command you're running and the _exact_ error message? – ForceBru Mar 22 '17 at 16:11
  • 'pip install GraphViz' And the error message is:InvocationException: GraphViz's executables not found – Saradamani Mar 22 '17 at 17:56

1 Answers1

1

Maybe try using conda....

I had the same problem when using pip install graphviz and displaying the plots in Jupyter. The problem is that doing pip install ... doesn't actually install GraphViz. See the documentation on PyPi (graphviz 0.7 : Python Package Index); you also have to install Graphviz:

This package facilitates the creation and rendering of graph descriptions in the DOT language of the Graphviz graph drawing software (repo) from Python.

...

Installation

This package runs under Python 2.7, and 3.3+, use pip to install:

$ pip install graphviz

To render the generated DOT source code, you also need to install Graphviz (download page).

This worked for me (again, using Jupyter, not tested in Spyder).

$ conda install python-graphviz
# Fetching package metadata .............
# Solving package specifications: 

# The following NEW packages will be INSTALLED:

#     graphviz:        2.38.0-3      bioconda
#     python-graphviz: 0.5.2-py36_0          

Then, in Jupyter:

import pydotplus 

d_tree = tree.DecisionTreeClassifier()
d_tree.fit(X_scaled, y)

dot_data = tree.export_graphviz(d_tree,
                                out_file=None,
                                filled=True,
                                rounded=True,
                                special_characters=True)  
graph = pydotplus.graph_from_dot_data(dot_data)  

from IPython.display import Image 
Image(graph.create_png()) 

enter image description here

Community
  • 1
  • 1
John
  • 1,335
  • 12
  • 17