Search code examples
pythongraphviztheanokeraspydot

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

  • 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.