Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 429
ishido Avatar asked Apr 27 '16 10:04

ishido


People also ask

How do I add Pydot to path?

Type conda install pydot graphviz in cmd, and then add the executables location directory C:\Anaconda3\pkgs\graphviz-2.38-hfd603c8_2\Library\bin\graphviz to your system path variable. That works! It works!

Does Pydot work with Python 3?

PyDotPlus is an improved version of the old pydot project that provides a Python Interface to Graphviz's Dot language. Differences with pydot: Compatible with PyParsing 2.0+. Python 2.7 - Python 3 compatible.


2 Answers

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.

like image 62
Dr. Snoopy Avatar answered Oct 09 '22 02:10

Dr. Snoopy


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.

like image 44
Tom Avatar answered Oct 09 '22 02:10

Tom