I'm trying to draw the keras model with the plotmodel.


I installed graphviz binaries with:

choco install graphviz

added path to the bin folder, and then I did:

pip install pydotplus
pip install graphviz


Getting this error when I try to execute:

from keras.models import Sequential
from keras.layers import Dense
from keras.utils.vis_utils import plot_model
model = Sequential()
model.add(Dense(2, input_dim=1, activation='relu'))
model.add(Dense(1, activation='sigmoid'))
plot_model(model, to_file='model_plot.png', show_shapes=True, show_layer_names=True)


ImportError: Failed to import pydot. You must install pydot and graphviz for pydotprint to work.

Can someone suggest some alternative to draw the keras model? I need to implement this for a CNN.

  • 1
    $\begingroup$ Did you install them for the correct python interpreter your code is running for? If you are using python 3.x as interpreter for the code and using pip install to install for package, it will installed for Python 2.x. $\endgroup$ Jan 16 '18 at 3:02
  • $\begingroup$ I am using python 3.x for keras 2, i wanted to install for python 3. I tried conda install too, even that gives same error $\endgroup$
    – Srihari
    Jan 18 '18 at 14:31
  • $\begingroup$ Try sudo pip3 install <package>. $\endgroup$ Jan 18 '18 at 15:05
  • $\begingroup$ pip3 install doesnt work on my anaconda $\endgroup$
    – Srihari
    Apr 6 '18 at 14:47

In addition to what you have already done, in my notebook I added two lines:

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


  • $\begingroup$ could someone tell me the correct way to reference other stack exchange posts in an answer $\endgroup$
    – Supamee
    Aug 14 '18 at 15:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.