Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ghost opened this issue Jul 13, 2016 · 36 comments
Closed

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

ghost opened this issue Jul 13, 2016 · 36 comments

Comments

@ghost
Copy link

ghost commented Jul 13, 2016

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!

@tboquet
Copy link
Contributor

tboquet commented Jul 13, 2016

You can try to install pydot-ng.

@ghost
Copy link
Author

ghost commented Jul 13, 2016

@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?

@oeway
Copy link
Contributor

oeway commented Jul 13, 2016

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.

@ghost
Copy link
Author

ghost commented Jul 14, 2016

@oeway The same error still exists....

@oeway
Copy link
Contributor

oeway commented Jul 14, 2016

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.

@litstrong
Copy link

@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 ?

@hadim
Copy link

hadim commented Aug 24, 2016

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 ?

@nouiz
Copy link
Contributor

nouiz commented Aug 24, 2016

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

Theano/Theano@aefd29d

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
#3210 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AALC-2SsuTQVuv3TGjf_fyi3uUkH9b22ks5qi5RfgaJpZM4JLCWx
.

@alainrichardt
Copy link

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

@zhourunlai
Copy link

zhourunlai commented Oct 18, 2016

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.

@eyaler
Copy link

eyaler commented Oct 20, 2016

pydot pre 1.2.0 do not support python 3...

@dotasheepliu
Copy link

I can run it after installing everything mentioned above.

@manashmandal
Copy link

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

pip install pydot-ng
sudo apt-get install graphviz

@Ellenisawake
Copy link

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?

@Tahsin-Mayeesha
Copy link

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.

@sookinoby
Copy link

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

@CreatCodeBuild
Copy link

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?

@sookinoby
Copy link

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

@CreatCodeBuild
Copy link

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

@HanyEjust
Copy link

HanyEjust commented Feb 5, 2017 via email

@sookinoby
Copy link

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

@naotokui
Copy link

naotokui commented Feb 8, 2017

on Mac, the following commands fixed the issue:

sudo pip install pydot-ng
brew install graphviz

@tomas-angles
Copy link

tomas-angles commented Feb 18, 2017

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.

@tboggs
Copy link

tboggs commented Mar 6, 2017

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

@jemshit
Copy link

jemshit commented Apr 17, 2017

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

@enduringstack
Copy link

try pydotplus

@diyali03
Copy link

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

@DerekGrant
Copy link

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

@stale
Copy link

stale bot commented Dec 11, 2017

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.

@stale stale bot added the stale label Dec 11, 2017
@eyaler
Copy link

eyaler commented Dec 11, 2017

no not stale unless a human says so

@stale stale bot removed the stale label Dec 11, 2017
@tharuniitk
Copy link

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.

@johnyf
Copy link
Contributor

johnyf commented Jan 20, 2018

Please see #5313 (comment) and #3216 (comment).

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

@pyaf
Copy link

pyaf commented Mar 1, 2018

pip install pydot-ng
conda install graphviz

@stajilov
Copy link

On macOS:
pip3 install pydot-ng
brew install graphviz

@johnyf
Copy link
Contributor

johnyf commented Apr 11, 2018

This issue has been addressed by #6398, specifically 54a417f. It can be closed.
Currently, there is no line in keras that calls the nonexistent find_graphviz:

def _check_pydot():
try:
# Attempt to create an image of a blank graph
# to check the pydot/graphviz installation.
pydot.Dot.create(pydot.Dot())
except Exception:
# pydot raises a generic Exception here,
# so no specific class can be caught.
raise ImportError('Failed to import pydot. You must install pydot'
' and graphviz for `pydotprint` to work.')

@wt-huang wt-huang closed this as completed Nov 2, 2018
@charusanmathi
Copy link

I had the same error on my MacBook and I installed pydot on Jupyter notebook

! pip install pydot

But grraphviz wouldn't work, so I went to graphviz documentations and installed home-brew on my terminal and then
used the following command

brew install graphviz

This worked well and I could see the plot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests