Theano: RuntimeError: Failed to import pydot.

Created on 11 Apr 2014  Â·  43Comments  Â·  Source: Theano/Theano

I just tried running this example http://deeplearning.net/software/theano/tutorial/printing_drawing.html for printing theano graphs from ipython, and I got this error. Anyone possibly know why? If I try accessing theano.printing.pydotprint, it has no trouble finding the attribute.

RuntimeError Traceback (most recent call last)
in ()
70 theano.printing.pydotprint(predict,
71 outfile="pics/logreg_pydotprint_predic.png",
---> 72 var_with_name_simple=True)
73 # before compilation
74 theano.printing.pydotprint_variables(prediction,
/usr/local/lib/python2.7/dist-packages/theano/printing.pyc in pydotprint(fct, outfile, compact, format, with_ids, high_contrast, cond_highlight, colorCodes, max_label_size, scan_graphs, var_with_name_simple, print_output_file, assert_nb_all_strings)
566
567 if not pydot_imported:
--> 568 raise RuntimeError("Failed to import pydot. You must install pydot"
569 " for pydotprint to work.")
570 return

Most helpful comment

Ok, thank you for your correction.
My problem is that I canimport theanoand import pydotwithout warnings.
But when I try to run this code

deeplearning.net/software/theano/tutorial/printing_drawing.html

I got these error:

Traceback (most recent call last):
  File "/Users/xinlianzhang/Downloads/Python/Theano graph.py", line 73, in <module>
    var_with_name_simple=True)
  File "/usr/local/lib/python2.7/site-packages/theano/printing.py", line 568, in pydotprint
    raise RuntimeError("Failed to import pydot. You must install pydot"
RuntimeError: Failed to import pydot. You must install pydot for `pydotprint` to work.

Any thoughts?

All 43 comments

Does "import pydot" work? If not, you need to install it, and also graphviz.

On Fri, Apr 11, 2014 at 3:44 PM, Matthew Dornfeld
[email protected]:

I just tried running this example
http://deeplearning.net/software/theano/tutorial/printing_drawing.htmlfor printing theano graphs from ipython, and I got this error. Anyone
possibly know why?

RuntimeError Traceback (most recent call last)
in ()
70 theano.printing.pydotprint(predict,
71 outfile="pics/logreg_pydotprint_predic.png",
---> 72 var_with_name_simple=True)
73 # before compilation
74 theano.printing.pydotprint_variables(prediction,
/usr/local/lib/python2.7/dist-packages/theano/printing.pyc in
pydotprint(fct, outfile, compact, format, with_ids, high_contrast,
cond_highlight, colorCodes, max_label_size, scan_graphs,
var_with_name_simple, print_output_file, assert_nb_all_strings)
566
567 if not pydot_imported:
--> 568 raise RuntimeError("Failed to import pydot. You must install pydot"
569 " for pydotprint to work.")
570 return

Reply to this email directly or view it on GitHubhttps://github.com/Theano/Theano/issues/1801
.

Ahhh thanks. I thought it lived inside theano.

I'll close this issue and you seam to understand the solution. If you have more questions, ask us.

hi, I have the same problem, but I am quite sure that my import pydot works

I'm not sure what "quite sure". So can you test this:

1 start python
2 run "import pydot"

Do this work? It must work, so you should be sure at 100% that this work
and the only way is to run it:)

On Wed, May 7, 2014 at 1:13 AM, coralzhang [email protected] wrote:

hi, I have the same problem, but I am quite sure that my import pydotworks

—
Reply to this email directly or view it on GitHubhttps://github.com/Theano/Theano/issues/1801#issuecomment-42390214
.

Ok, thank you for your correction.
My problem is that I canimport theanoand import pydotwithout warnings.
But when I try to run this code

deeplearning.net/software/theano/tutorial/printing_drawing.html

I got these error:

Traceback (most recent call last):
  File "/Users/xinlianzhang/Downloads/Python/Theano graph.py", line 73, in <module>
    var_with_name_simple=True)
  File "/usr/local/lib/python2.7/site-packages/theano/printing.py", line 568, in pydotprint
    raise RuntimeError("Failed to import pydot. You must install pydot"
RuntimeError: Failed to import pydot. You must install pydot for `pydotprint` to work.

Any thoughts?

Run this:

import pydot
print pydot.find_graphviz()

Give me the output.

pydot isn't a self contained program. It need a c library called graphviz.
I think you didn't install it. The code above will check that. Check how to
install graphviz in your system.

Fred

On Wed, May 7, 2014 at 9:51 AM, coralzhang [email protected] wrote:

Ok, thank you for your correction.
My problem is that I canimport theanoand import pydotwithout warnings.
But when I try to run this code

deeplearning.net/software/theano/tutorial/printing_drawing.html

I got these error:

Traceback (most recent call last):
File "/Users/xinlianzhang/Downloads/Python/Theano graph.py", line 73, in
var_with_name_simple=True)
File "/usr/local/lib/python2.7/site-packages/theano/printing.py", line 568, in pydotprint
raise RuntimeError("Failed to import pydot. You must install pydot"
RuntimeError: Failed to import pydot. You must install pydot for pydotprint to work.

Any thoughts?

—
Reply to this email directly or view it on GitHubhttps://github.com/Theano/Theano/issues/1801#issuecomment-42428963
.

This is strange... In python, I have

>>> print pydot.find_graphviz()
None

But in the terminal I have

localhost:~ xinlianzhang$ pip list
Cython (0.20.1)
graphviz (0.3.1)
matplotlib (1.3.1)
....

Here is the web page of that graphviz. This is a python package called
graphviz. Bad choice of name. You need to install the c version of
graphvis. See this web page:

https://pypi.python.org/pypi/graphviz/0.3.3

From the command line, the command "dot" should work. Look into you OS to
know if it provide graphviz. If so, it will be probably the c version.

Fred

On Wed, May 7, 2014 at 10:22 AM, coralzhang [email protected]:

This is strange... In python, I have

print pydot.find_graphviz()
None

But in the terminal I have

localhost:~ xinlianzhang$ pip list
Cython (0.20.1)
graphviz (0.3.1)
matplotlib (1.3.1)
....

—
Reply to this email directly or view it on GitHubhttps://github.com/Theano/Theano/issues/1801#issuecomment-42432866
.

I used the code from the page you gave me, dot is working.
Could you please tell me how can i check if I have graphviz in my system? I am using Mac 10.9.

If the command line "dot" is installed, graphviz (the c version) should be
installed. So it seam you have hit a bug in pydot. Try to contact them or
update pydot. There was a bug in the past, maybe they had fixed it. But I
forgot what this bug was, so it could be unrelated.

Fred

On Wed, May 7, 2014 at 10:54 AM, coralzhang [email protected]:

I used the code from the page you gave me, dot is working.
Could you please tell me how can i check if I have graphviz in my system?
I am using Mac 10.9.

—
Reply to this email directly or view it on GitHubhttps://github.com/Theano/Theano/issues/1801#issuecomment-42437227
.

Thank you so much for you help. I will just go ahead and try to install this c version graphviz first and see how it goes with pydot.

Hey, dear nouiz. I did as you suggested, and my problem is solved. It turns out that the graphviz is just an interface for the tool `Graphviz``. Thank you again for your help!

Thanks for the above - I had the same problem on Ubuntu, reinstalled pydot (pip install pydot) and installed graphviz (sudo apt-get install graphviz) and it is working now.

if you are using IDE like spyder, you should restart the console inside it(such as IPython console or simple terminal) after install python-pydot

I also have faced a similar situation.............

Just to summarize,

  1. install C-version of graphviz using 'sudo apt-get install graphviz' if ubuntu, 'brew install graphviz' if OSX
  2. pip install pydot
    ( if it fails to import pydot in later stage, http://stackoverflow.com/questions/15951748/pydot-and-graphviz-error-couldnt-import-dot-parser-loading-of-dot-files-will)
  3. pip install graphviz

cheers,

@chrischoy brew install graphviz fix my problems! Thank you :)

@coralzhang
You should install a C-version graphviz,like brew install graphviz on mac;
and after that you can get some graphviz info like

print pydot.find_graphviz()
{'fdp': '/usr/local/bin/fdp', 'twopi': '/usr/local/bin/twopi', 'neato': '/usr/local/bin/neato', 'dot': '/usr/local/bin/dot', 'circo': '/usr/local/bin/circo'}

The python 3 compatible version of pydot is called pydot-ng. Try to install
that one and use Theano development version.
Le 30 oct. 2015 01:26, "uclyyu" [email protected] a écrit :

Anyone here using python 3.4.x?

I am having the same issue on Ubuntu 15.04.
Having followed through the instructions above: apt-get install graphviz
and pip3 install pydot.
The pydot installation doesn't work for me, possibly not python 3.x
compatible.

So I switched to pip3 install pydot3k, which gives:

import pydot

print(pydot.find_graph())
{'circo': '/usr/bin/circo',
'dot': '/usr/bin/dot',
'fdp': '/usr/bin/fdp',
'neato': '/usr/bin/neato',
'sfdp': '/usr/bin/sfdp',
'twopi': '/usr/bin/twopi'}

Unfortunately, the same issue mentioned by @coralzhang
https://github.com/coralzhang persists. Any ideas?

Many thanks!

—
Reply to this email directly or view it on GitHub
https://github.com/Theano/Theano/issues/1801#issuecomment-152420499.

This is awesome! I was having a similar problem and did not realize to install C package at all.
Thanks @nouiz !!

Hi !

I just faced the problem because I had pydot but not graphviz (facepalm). I think that the exception
"Failed to import pydot. You must install pydot" is misleading. The exception can be raised for two reasons (cf start of printing.py) :

  • You do not have pydot
  • You have pydot and not graphviz. In this case, you read the exception and try to import pydot but nothing goes wrong since it can be imported without graphviz installed.

Thereforefore, the exception could be clearer with "you must install pydot and graphviz"

Kind regards,
Laurent

Had the same issue with missing graphviz and it took me longer to fix than it should have since I had to look at the Theano source to understand what was wrong. The ImportError is really misleading.

In the master of Theano, the error is:

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

What do you suggest we tell? It already tell that graphviz must be there.
If you have better message to add, we can change it.

thanks

On Fri, Mar 18, 2016 at 11:29 AM, Carl Thomé [email protected]
wrote:

Had the same issue with missing graphviz and it took me longer to fix than
it should have since I had to look at the Theano source to understand what
was wrong. The ImportError is really misleading.

—
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
https://github.com/Theano/Theano/issues/1801#issuecomment-198409552

Good find. Do you want to make a PR and have your name in the history of
git commit of Theano?

Otherwise, I can do it.

On Fri, Mar 18, 2016 at 1:19 PM, Carl Thomé [email protected]
wrote:

The same clarification could be added here as well:
https://github.com/Theano/Theano/blob/458e1594c9407ac1fd2a7b6751c6ee2385c5d33f/theano/d3viz/formatting.py#L54

—
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
https://github.com/Theano/Theano/issues/1801#issuecomment-198460161

Yey, the epic commit history! I'll do a pr now. :+1:

brew install graphviz
which I did to resolve this issue.

what is the command for cmd, windows user (win7)?

i tried pip install graphviz, in cmd it is installed, but in spyder I get the result none.

I even installed graphviz for win, but still same problem in spyder result is none
[(http://www.graphviz.org/Download_windows.php)]

It seem spyder don't use the same python as the default one for your OS. I don't use spyder, so I can't help more then tell to check which python spyder is using and install it for that python version with pip. Use the pip in the same folder as the python version that spyder use.

I faced this issue.

Did the 3 steps

  1. brew install graphviz
  2. pip install pydot
  3. pip install graphviz

When I do :
import pydot
print pydot.find_graphviz()

I get "AttributeError: 'module' object has no attribute 'find_graphviz"
I tried http://stackoverflow.com/questions/38446771/importing-theano-attributeerror-module-object-has-no-attribute-find-graphvi

Works smoothly !

Newer pydot version don't have that attribute anymore.

Use THeano dev version, we accept newer pydot version now.

On Tue, Oct 18, 2016 at 8:24 AM, Anuj Gupta [email protected]
wrote:

I seeming to be still facing this issue.

Did the 3 steps

  1. brew install graphviz
  2. pip install pydot
  3. pip install graphviz

When I do :
import pydot
print pydot.find_graphviz()

I get "AttributeError: 'module' object has no attribute 'find_graphviz"
I tried http://stackoverflow.com/questions/38446771/importing-
theano-attributeerror-module-object-has-no-attribute-find-graphvi
but still getting the error
"AttributeError: 'module' object has no attribute 'find_graphviz"

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/Theano/Theano/issues/1801#issuecomment-254491444, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AALC-3XPdleh1d8Xvn5dzu8F2D9qMPDWks5q1LqagaJpZM4Bx0ib
.

I have similar error when I run
"from keras.utils.visualize_util import plot"

File "C:UsersLuaAnaconda2libsite-packageskeras-1.1.1-py2.7.eggkerasutilsvisualize_util.py", line 12, 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, and theano.
When I ran "pydot.find_graphviz()":
Traceback (most recent call last):

File "", line 1, in
pydot.find_graphviz()

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

I tried several pydot versions (pydot 1.2.3, pydot-ng, pydot 1.2.2, and pydot 1.1.0), and graphviz versions (0.5.1 by pip install, 2.38.0-2 by anaconda), but nothing worked.
I use anaconda 4.1.1, python 2.7 in win 10 64-bit (the code was ran in spyder).

Thank you in advance.

sudo apt-get install graphviz
pip install graphviz
pip install pydot==1.1.0

It works on Ubuntu 16.04.

On mac:
pip install pydot-ng and brew install graphviz worked for me :)

  • Thanks!

Hey guys :)

I am on ubuntu 16.04, working with jupyter notebook with keras and Tensorflow backend.

when i install pyplot using "sudo apt-get install pyplot" i get:

"Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package pyplot"

and naturally, when i run " from keras.utils import plot_model
plot_model(model, to_file='model.png')"

inside the notebook, i get the following error:
"ImportError: Failed to import pydot. You must install pydot and graphviz for pydotprint to work."

How do i correctly install the pyplot and graphviz?

Thanks :)

brew install graphviz
solve my problem. THX everyone

Btw I still have the same problem ... I am trying to install graphviz on windows, and I did install the windows version of the software (https://graphviz.gitlab.io/_pages/Download/Download_windows.html) but i do not know what to do with the patch in order to make it work.
I get exception when I do:
print pydot.find_graphviz()

Pydot import does work,

I was able to solve it like this:

sudo apt-get install graphviz
pip install pydot
pip install graphviz

On linux it is easy, but for windows it is more dificult.

I think conda version of pydot or pydot-ng include graphviz.

Was this page helpful?
0 / 5 - 0 ratings