Keras: AttributeError: module 'pydot' has no attribute 'find_graphviz'

Created on 13 Jul 2016  Â·  35Comments  Â·  Source: keras-team/keras

My os is Ubuntu 14.04 and python version is 3.5. I just simply did what the document said:

from keras.utils.visualize_util import plot

And what I got is:

AttributeError                            Traceback (most recent call last)
<ipython-input-90-65016ddab3cd> in <module>()
----> 1 from keras.utils.visualize_util import plot

/home/lcc/anaconda3/envs/sensequant/lib/python3.5/site-packages/keras/utils/visualize_util.py in <module>()
      5     # fall back on pydot if necessary
      6     import pydot
----> 7 if not pydot.find_graphviz():
      8     raise RuntimeError('Failed to import pydot. You must install pydot'
      9                        ' and graphviz for `pydotprint` to work.')

AttributeError: module 'pydot' has no attribute 'find_graphviz'

Indeed I have ensured that pydot, pydotplus, graphviz have been installed as I could import them properly. Do you know how to fix it? Thank you in advance!

Most helpful comment

pydot-ng will give you pydot that satisfies the keras package, use
pip install pydot-ng
to install it in your virtualenv.

On ubuntu you need to have the "dot" executable in your PATH, you can do this by installing the graphviz package:
apt-get install graphviz

All 35 comments

You can try to install pydot-ng.

@tboquet Thanks for your help! But this time I got this error: RuntimeError: Failed to import pydot. You must install pydot and graphviz forpydotprintto work. But I have installed pydot and graphviz already. Do you have any idea about that?

Here is how I fix the problem:
sudo pip install pydot==1.0.2 --upgrade
It seems pydot don't provide a function named find_graphviz anymore.

@oeway The same error still exists....

Could you try to install from here: https://github.com/nlhepler/pydot

As you can see from here https://github.com/nlhepler/pydot/blob/master/pydot/__init__.py#L474 , they do have find_graphviz function.

@rylanchiu
I had same problem like you had.

I think it is caused by could not find the graphviz although graphviz is installed.

When I use brew install graphviz, there was a warning said not linked.

It works and linked successful after I tried to uninstall it and re-install. Or you can try brew link ?

Would it be possible to add support for pydotplus since it's available in conda-forge for python 3.5 while pydot is not available with conda ?

The problem is that pydot changed a small part of its interface. We fixed
that in Theano in this commit:

https://github.com/Theano/Theano/pull/4747/commits/aefd29dbc64a972071343d4fc786013aff5a4625

It would be easy to do the same in keras to suport its newer version.

On Tue, Aug 23, 2016 at 8:46 PM, Hadrien Mary [email protected]
wrote:

Would it be possible to add support for pydotplus since it's available in
conda-forge for python 3.5 while pydot is not available with conda ?

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/fchollet/keras/issues/3210#issuecomment-241926324,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AALC-2SsuTQVuv3TGjf_fyi3uUkH9b22ks5qi5RfgaJpZM4JLCWx
.

pydot-ng will give you pydot that satisfies the keras package, use
pip install pydot-ng
to install it in your virtualenv.

On ubuntu you need to have the "dot" executable in your PATH, you can do this by installing the graphviz package:
apt-get install graphviz

First, the pydot will find_graphviz, in line 7 of visualize_util.py.
Then, it will check these PATH to judge whether the graphviz exists, in line 605 of pydot_ng/__init__.py.

'/usr/bin', '/usr/local/bin',
            '/opt/local/bin',
            '/opt/bin', '/sw/bin', '/usr/share',
            '/Applications/Graphviz.app/Contents/MacOS/'

So, we should install graphviz by these way:

  1. download APP, this will put to /Applications/Graphviz.app/Contents/MacOS/;
  2. command brew install graphviz, this will create the link to /usr/local/bin.

pydot pre 1.2.0 do not support python 3...

I can run it after installing everything mentioned above.

I faced similar problem and executing the following commands solved my problem.

pip install pydot-ng
sudo apt-get install graphviz

Same issue here...
Seems that pydot-ng supports up to Python 3.4?
And pydot 1.1.0 not available in conda...
For Keras to work properly with Python 3.5, any consideration to embed pydotplus?

http://stackoverflow.com/questions/36869258/how-to-use-graphviz-with-anaconda-spyder

Downloading Graphviz from their website (msi version in my case given I'm on windows) and adding
C:\Program Files (x86)\Graphviz2.38\bin to my system variables in PATH worked for me.

Thanks @Tahsin-Mayeesha . This is the right solution.

I tried install all the requirement both from pip and from binary installation on system and I configured my PATH. It doesn't work.
I am using Windows 10, Python 3.5.2 |Anaconda 4.0.0 (64-bit)| (default, Jul 5 2016, 11:41:13) [MSC v.1900 64 bit (AMD64)] on win32

Regardless, how useful is this visualization?
Is there any third-party library I can use?

What is the error you getting? I
Visualization is not very useful - sample - https://github.com/sookinoby/behavior-cloning/blob/master/images/model.png
I edited the image to wrap around.

model.summary() is more useful.
I don't know any third party library. `

@sookinoby

    from keras.utils.visualize_util import plot
  File "D:\Anaconda3\lib\site-packages\keras\utils\visualize_util.py", line 13, 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 can import pydot, graphviz.
I can also use dot at Terminal.

pip install pydot-ng
conda install graphviz

pip uninstall pyparsing
pip install -Iv
https://pypi.python.org/packages/source/p/pyparsing/pyparsing-1.5.7.tar.gz#md5=9be0fcdcc595199c646ab317c1d9a709
pip install pydot

conda install -c https://conda.binstar.org/sstromberg pydot

conda install GraphViz

On Sun, Feb 5, 2017 at 9:04 AM, Albert X.W. notifications@github.com
wrote:

@sookinoby https://github.com/sookinoby

from keras.utils.visualize_util import plot

File "D:\Anaconda3\lib\site-packages\keras\utilsvisualize_util.py", line 13, in
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 can import pydot, graphviz.
I can also use dot at Terminal.

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/fchollet/keras/issues/3210#issuecomment-277501697,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ARxwS88xOy6b-WuEsD0p0CjQhfW31QvRks5rZXRogaJpZM4JLCWx
.

--


Hany A. EL-Ghaish

E-JUST University
*PhD Candidate at School of Communication and Computer Engineering,
Egypt-Japan University of Science and Technology *
M. 01004393715

install - http://www.graphviz.org/Download_windows.php. Add the bin folder to windows path. Everything will work fine.

on Mac, the following commands fixed the issue:

sudo pip install pydot-ng
brew install graphviz

On Mac: If you are working in a virtual environment with Anaconda (always do that to avoid messing up the python in your OS):

1) source activate virtualenv_name
2) conda install graphviz
3) pip install pydot-ng

And run your script from terminal. As a sanity check (in terminal):
1) python
2) import pydot_ng as pydot
3) pydot.find_graphviz()

The output should be a string similar to: "{'dot': 'your_path/bin/dot', 'twopi': ..."

But, @sookinoby is right, model.summary() is much more useful.

I have this issue with python3 on ubuntu 16.04. Since I know I have the necessary packages installed, I do the following to avoid the error:

import pydot
pydot.find_graphviz = lambda: True

For Mac, we need brew install graphviz besides pip install graphviz

try pydotplus

I have this issue with ubuntu 16.04
But raises import error:

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

This can help me

pip install pydot-ng
sudo apt-get install graphviz

For window, this because python can't find graphviz path, in pydot_ng _init_.py
It just search path for linux and Mac user, will can fix this problem by add path

for path in (
            '/usr/bin', '/usr/local/bin',
            '/opt/local/bin',
            '/opt/bin', '/sw/bin', '/usr/share',
            '/Applications/Graphviz.app/Contents/MacOS/'
            ):
        progs = __find_executables(path)
        if progs is not None:
            print("Used path")
            return progs

We should modify to

    for path in (
            '/usr/bin', '/usr/local/bin',
            '/opt/local/bin',
            '/opt/bin', '/sw/bin', '/usr/share',
            '/Applications/Graphviz.app/Contents/MacOS/'
            ):
        myGraphVizPath='D:\\Programming\\Graphviz2.38\\bin'#my graphviz path 
        progs = __find_executables(myGraphVizPath)
        if progs is not None:
            print("Used path")
            return progs

    # Failed to find GraphViz
    return None

http://blog.csdn.net/u014376030/article/details/69945238

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 30 days if no further activity occurs, but feel free to re-open a closed issue if needed.

no not stale unless a human says so

HI @tomas-angles :
I followed the procedure given in your comments for installing pydot, graphviz. Every thing works fine as far as sanity check is concerned(in terminal):

python
import pydot_ng as pydot
pydot.find_graphviz()

import pydot_ng
pydot_ng.find_graphviz()
{'twopi': '/usr/bin/twopi', 'fdp': '/usr/bin/fdp', 'circo': '/usr/bin/circo', 'neato': '/usr/bin/neato', 'dot': '/usr/bin/dot', 'sfdp': '/usr/bin/sfdp'}

But the following lines of code in python script run under keras leaves an error below again and again:

from keras.utils import plot_model
plot_model(model1, to_file='model.png')

plot_model(model1, to_file='model.png')
File "/home/tharun/anaconda2/envs/kerasdl/lib/python2.7/site-packages/keras/utils/vis_utils.py", line 132, in plot_model
dot = model_to_dot(model, show_shapes, show_layer_names, rankdir)
File "/home/tharun/anaconda2/envs/kerasdl/lib/python2.7/site-packages/keras/utils/vis_utils.py", line 52, in model_to_dot
_check_pydot()
File "/home/tharun/anaconda2/envs/kerasdl/lib/python2.7/site-packages/keras/utils/vis_utils.py", line 27, in _check_pydot
raise ImportError('Failed to import pydot. You must install pydot'
ImportError: Failed to import pydot. You must install pydot and graphviz for pydotprint to work.

Please see https://github.com/keras-team/keras/issues/5313#issuecomment-278457653 and https://github.com/keras-team/keras/issues/3216#issuecomment-232478002.

Comments about installation: https://stackoverflow.com/a/47209738/1959808
(GraphViz is needed; the Python package graphviz is unrelated to pydot).

pip install pydot-ng
conda install graphviz

On macOS:
pip3 install pydot-ng
brew install graphviz

This issue has been addressed by https://github.com/keras-team/keras/pull/6398, specifically 54a417f6167841bebcb567c5ac98724f2038afa7. It can be closed.
Currently, there is no line in keras that calls the nonexistent find_graphviz:

https://github.com/keras-team/keras/blob/e73199d413395d7ede0dd86c06f7a9ad2d1fee17/keras/utils/vis_utils.py#L23-L32

Was this page helpful?
0 / 5 - 0 ratings