Keras: "RuntimeError: Failed to import pydot." after installing graphviz and pydot

I'm using Anaconda Python 2.7 on windows 10

I was planning on doing Keras visualization so (whilst spyder was open) I opened the Anaconda command prompt and pip installed graphviz and pydot. Now when I try run the following:

from keras.models import Sequential

or any sort of "from keras." , I get the error:

ImportError: cannot import name gof

I have uninstalled and reinstalled Keras, Graphviz and pydot. i am using the development version of theano. I cannot find a fix.

P.S

If I uninstall graphviz and pydot, keras works again

EDIT

After uninstalling anaconda and reinstalling it including theano, keras, graphviz and pydot I now get the following error:

from keras.utils.visualize_util import plot

Using Theano backend.
Using gpu device 0: GeForce GTX 970M (CNMeM is disabled, cuDNN not available)
Traceback (most recent call last):

  File "<ipython-input-1-65016ddab3cd>", line 1, in <module>
  from keras.utils.visualize_util import plot

  File "C:\Anaconda2\lib\site-packages\keras\utils\visualize_util.py", line  8, in <module>
  raise RuntimeError('Failed to import pydot. You must install pydot'

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

I used pip install graphviz and pip install git+https://github.com/nlhepler/pydot.git


Solution 1:

The error message is a bit misleading, as you can see here. The problem is that graphviz is not installed.

But you mention that graphviz was installed using pip. This is also misleading, since that graphviz package is just a python wrapper, and the graphviz binaries have to be installed separately for the python wrapper to work.

Solution 2:

If you are using an Anaconda environment, you'd better install pydotplus and graphviz via conda install.

conda install graphviz
conda install pydotplus

Note: You'd better update your Keras to the newest version (2.0.9+), it can automatically check and choose which one of pydotplus,pydot-ng,pydot to be used. pydot-ng has been unmaintained for a long time, and it only supports py3.4- and py2.7.

Solution 3:

What I did is followed.

import keras
import pydotplus
from keras.utils.vis_utils import model_to_dot
keras.utils.vis_utils.pydot = pydot

plot_model(your_model_name, to_file='model.png')

That's worked for me. On mac Anaconda python=3.6.8