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

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

Closed
jbarrigapartarrieu opened this issue Jan 27, 2018 · 22 comments

Comments

@jbarrigapartarrieu
Copy link

@jbarrigapartarrieu jbarrigapartarrieu commented Jan 27, 2018

Hi everyone!
Trying to run the second block in run.ipynb (start learning process) but I get the following error. I have Python 3.5 installed. Both pydot and graphviz are installed in the proper environment. This is the error I get. Thanks in advance for your help.


FileNotFoundError Traceback (most recent call last)
~/anaconda2/envs/py35/lib/python3.5/site-packages/pydot.py in create(self, prog, format)
1877 shell=False,
-> 1878 stderr=subprocess.PIPE, stdout=subprocess.PIPE)
1879 except OSError as e:

~/anaconda2/envs/py35/lib/python3.5/subprocess.py in init(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds)
675 errread, errwrite,
--> 676 restore_signals, start_new_session)
677 except:

~/anaconda2/envs/py35/lib/python3.5/subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, start_new_session)
1288 err_msg += ': ' + repr(orig_executable)
-> 1289 raise child_exception_type(errno_num, err_msg)
1290 raise child_exception_type(err_msg)

FileNotFoundError: [Errno 2] No such file or directory: 'dot'

During handling of the above exception, another exception occurred:

Exception Traceback (most recent call last)
~/anaconda2/envs/py35/lib/python3.5/site-packages/keras/utils/vis_utils.py in _check_pydot()
26 # to check the pydot/graphviz installation.
---> 27 pydot.Dot.create(pydot.Dot())
28 except Exception:

~/anaconda2/envs/py35/lib/python3.5/site-packages/pydot.py in create(self, prog, format)
1882 '"{prog}" not found in path.'.format(
-> 1883 prog=prog))
1884 else:

Exception: "dot" not found in path.

During handling of the above exception, another exception occurred:

ImportError Traceback (most recent call last)
in ()
39 #copy the config file to the run folder
40 copyfile('./config.py', run_folder + 'config.py')
---> 41 plot_model(current_NN.model, to_file=run_folder + 'models/model.png', show_shapes = True)
42
43 print('\n')

~/anaconda2/envs/py35/lib/python3.5/site-packages/keras/utils/vis_utils.py in plot_model(model, to_file, show_shapes, show_layer_names, rankdir)
133 'LR' creates a horizontal plot.
134 """
--> 135 dot = model_to_dot(model, show_shapes, show_layer_names, rankdir)
136 _, extension = os.path.splitext(to_file)
137 if not extension:

~/anaconda2/envs/py35/lib/python3.5/site-packages/keras/utils/vis_utils.py in model_to_dot(model, show_shapes, show_layer_names, rankdir)
54 from ..models import Sequential
55
---> 56 _check_pydot()
57 dot = pydot.Dot()
58 dot.set('rankdir', rankdir)

~/anaconda2/envs/py35/lib/python3.5/site-packages/keras/utils/vis_utils.py in _check_pydot()
29 # pydot raises a generic Exception here,
30 # so no specific class can be caught.
---> 31 raise ImportError('Failed to import pydot. You must install pydot'
32 ' and graphviz for pydotprint to work.')
33

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

@DataInformer

This comment has been minimized.

@jdori

This comment has been minimized.

Copy link

@jdori jdori commented Jan 30, 2018

@jbarrigapartarrieu make sure you have Graphviz installed separately on your system, not just in your project directory. You can find source and executable package installers here: https://www.graphviz.org/download/

@nickyongzhang

This comment has been minimized.

Copy link

@nickyongzhang nickyongzhang commented Feb 12, 2018

Same issue for me. Thanks to @jdori , I use homebrew to install graphviz and the problem sovled.

@davidADSP

This comment has been minimized.

Copy link
Contributor

@davidADSP davidADSP commented Mar 25, 2018

brew install graphviz
or equivalent should fix this

@davidADSP davidADSP closed this Mar 25, 2018
@ujinyoung

This comment has been minimized.

Copy link

@ujinyoung ujinyoung commented Sep 11, 2018

@DataInformer thank you

@MirkosMartins

This comment has been minimized.

Copy link

@MirkosMartins MirkosMartins commented Sep 13, 2018

I solved with this 2 steps:

  • install Graphviz after download installer (https://www.graphviz.org/)
  • insert in code this two lines:
    import os
    os.environ["PATH"] += os.pathsep + 'C:/Program Files (x86)/Graphviz2.38/bin/'
Shatterblade pushed a commit to Shatterblade/DeepReinforcementLearning that referenced this issue Oct 9, 2018
@Kiran-kkt

This comment has been minimized.

Copy link

@Kiran-kkt Kiran-kkt commented Feb 21, 2019

@MirkosMartins The issue still persists for me even after doing the same as you did.

@MirkosMartins

This comment has been minimized.

Copy link

@MirkosMartins MirkosMartins commented Feb 25, 2019

@MirkosMartins The issue still persists for me even after doing the same as you did.

Kiran-kkt, could you send me the error message?

@Kiran-kkt

This comment has been minimized.

Copy link

@Kiran-kkt Kiran-kkt commented Feb 27, 2019

@MirkosMartins The issue still persists for me even after doing the same as you did.

Kiran-kkt, could you send me the error message?

Error message:


FileNotFoundError

                     Traceback (most recent call last)

C:\Program Files\Anaconda3\lib\site-packages\pydot.py in create(self, prog, format, encoding)
1914 arguments=arguments,
-> 1915 working_dir=tmp_dir,
1916 )

C:\Program Files\Anaconda3\lib\site-packages\pydot.py in call_graphviz(program, arguments, working_dir, **kwargs)
135 stdout=subprocess.PIPE,
--> 136 **kwargs
137 )

C:\Program Files\Anaconda3\lib\subprocess.py in init(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds)
946 errread, errwrite,
--> 947 restore_signals, start_new_session)
948 except:

C:\Program Files\Anaconda3\lib\subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_start_new_session)
1223 cwd,
-> 1224 startupinfo)
1225 finally:

FileNotFoundError: [WinError 2] Das System kann die angegebene Datei nicht finden

During handling of the above exception, another exception occurred:

FileNotFoundError Traceback (most recent call last)
C:\Program Files\Anaconda3\lib\site-packages\keras\utils\vis_utils.py in _check_pydot()
25 # to check the pydot/graphviz installation.
---> 26 pydot.Dot.create(pydot.Dot())
27 except OSError:

C:\Program Files\Anaconda3\lib\site-packages\pydot.py in create(self, prog, format, encoding)
1921 prog=prog)
-> 1922 raise OSError(*args)
1923 else:

FileNotFoundError: [WinError 2] "dot" not found in path.

During handling of the above exception, another exception occurred:

OSError Traceback (most recent call last)
in ()
7 model.add(Dense(2, input_dim=1, activation='relu'))
8 model.add(Dense(1, activation='sigmoid'))
----> 9 plot_model(model, to_file='model_plot.png', show_shapes=True, show_layer_names=True)

C:\Program Files\Anaconda3\lib\site-packages\keras\utils\vis_utils.py in plot_model(model, to_file, show_shapes, show_layer_names, rankdir)
130 'LR' creates a horizontal plot.
131 """
--> 132 dot = model_to_dot(model, show_shapes, show_layer_names, rankdir)
133 _, extension = os.path.splitext(to_file)
134 if not extension:

C:\Program Files\Anaconda3\lib\site-packages\keras\utils\vis_utils.py in model_to_dot(model, show_shapes, show_layer_names, rankdir)
53 from ..models import Sequential
54
---> 55 _check_pydot()
56 dot = pydot.Dot()
57 dot.set('rankdir', rankdir)

C:\Program Files\Anaconda3\lib\site-packages\keras\utils\vis_utils.py in _check_pydot()
27 except OSError:
28 raise OSError(
---> 29 'pydot failed to call GraphViz.'
30 'Please install GraphViz (https://www.graphviz.org/) '
31 'and ensure that its executables are in the $PATH.')

OSError: pydot failed to call GraphViz.Please install GraphViz (https://www.graphviz.org/) and ensure that its executables are in the $PATH.

Sample code:

from keras.models import Sequential
from keras.layers import Dense
from keras.utils.vis_utils import plot_model
import os
os.environ["PATH"] += os.pathsep + 'C:/Program Files (x86)/Graphviz2.38/bin/'
model = Sequential()
model.add(Dense(2, input_dim=1, activation='relu'))
model.add(Dense(1, activation='sigmoid'))
plot_model(model, to_file='model_plot.png', show_shapes=True, show_layer_names=True)

User path variable:

user varaibles

@24rochak

This comment has been minimized.

Copy link

@24rochak 24rochak commented Mar 4, 2019

If you have setup the PATH variable in Windows and still the same error shows up in any IDE like PyCharm, then restart your IDE. It fixes the error as the PATH variable does not get updated dynamically.

@onomatopeia

This comment has been minimized.

Copy link

@onomatopeia onomatopeia commented Mar 23, 2019

@Kiran-kkt You need to install Graphviz with conda, and not from the binaries.
See here for syntax: https://anaconda.org/anaconda/graphviz
It's probably better to uninstall Graphviz first, but actually I'm not sure if there would be any clash.

Reason: Pydot checks whether you have graphviz installed by calling the dot executable. On Windows it appends an extension "exe" unless you have Anaconda, in which case it appends "bat". You can check that your Graphviz installation from binaries has only "dot.exe". So since pydot tries to execute "dot.bat" you;'re getting the error.
You can see it in Pydot's sources here: https://github.com/pydot/pydot/blob/master/pydot.py#L103-L108

@Kiran-kkt

This comment has been minimized.

Copy link

@Kiran-kkt Kiran-kkt commented Mar 26, 2019

@onomatopeia I've installed Graphviz via conda and now I get a new error like this.

Error message:


AssertionError Traceback (most recent call last)
in
7 model.add(Dense(2, input_dim=1, activation='relu'))
8 model.add(Dense(1, activation='sigmoid'))
----> 9 plot_model(model, to_file='model_plot.png', show_shapes=True, show_layer_names=True)

C:\ProgramData\Anaconda3\envs\masterprjt_v_1.0\lib\site-packages\keras\utils\vis_utils.py in plot_model(model, to_file, show_shapes, show_layer_names, rankdir)
130 'LR' creates a horizontal plot.
131 """
--> 132 dot = model_to_dot(model, show_shapes, show_layer_names, rankdir)
133 _, extension = os.path.splitext(to_file)
134 if not extension:

C:\ProgramData\Anaconda3\envs\masterprjt_v_1.0\lib\site-packages\keras\utils\vis_utils.py in model_to_dot(model, show_shapes, show_layer_names, rankdir)
53 from ..models import Sequential
54
---> 55 _check_pydot()
56 dot = pydot.Dot()
57 dot.set('rankdir', rankdir)

C:\ProgramData\Anaconda3\envs\masterprjt_v_1.0\lib\site-packages\keras\utils\vis_utils.py in _check_pydot()
24 # Attempt to create an image of a blank graph
25 # to check the pydot/graphviz installation.
---> 26 pydot.Dot.create(pydot.Dot())
27 except OSError:
28 raise OSError(

C:\ProgramData\Anaconda3\envs\masterprjt_v_1.0\lib\site-packages\pydot.py in create(self, prog, format, encoding)
1883 out=stdout_data,
1884 err=stderr_data))
-> 1885 assert p.returncode == 0, p.returncode
1886 return stdout_data

AssertionError: 1

Line #24 #25 suggests me that its checking for graphviz installation. I've also looked up in stackoverflow and I see the same answer

I also tried this by installing python package anaconda python-graphviz but of no use.

I don't understand why this problem still exsists it's kind of wierd.

@onomatopeia

This comment has been minimized.

Copy link

@onomatopeia onomatopeia commented Mar 26, 2019

Sorry to hear that @Kiran-kkt, this solution worked on my machine :(.
Anyway, the error you're getting says that the subprocess ended with exit code = 1.

Are you also getting an error message (just before the AssertionError) - something like

message = '"{prog}" with args {arguments} returned code: {code}\n\n'
                'stdout, stderr:\n {out}\n{err}\n'

Maybe that gives more details as to what is going on?

This message is formed and displayed in the latest version of pydot, but from the line numbers in your stack trace I can see that you have some older version. Could you check what version that is? (e.g. by running pip freeze from the command line inside the virtual environment)

@sakurakhadag

This comment has been minimized.

Copy link

@sakurakhadag sakurakhadag commented Mar 27, 2019

@onomatopeia Thanks. Installing with conda worked for me.

@Kiran-kkt

This comment has been minimized.

Copy link

@Kiran-kkt Kiran-kkt commented Mar 27, 2019

@onomatopeia Here is the message

"dot" with args ['-Tps', 'C:\\Users\\TUNUGU~1\\AppData\\Local\\Temp\\tmp4dwfnf5z'] returned code: 1

stdout, stderr:
 b''
b''

pydot version is 1.4.1 and graphviz version is 2.38

@onomatopeia

This comment has been minimized.

Copy link

@onomatopeia onomatopeia commented Mar 27, 2019

Ah, that is so unhelpful!
Ok, some last checks before I give up.
In the command line activate your virtual env, type where dot. This is just a sanity check, the path should be something like <path_to_anaconda>\envs\<your_virtual_env>\Library\bin\dot.bat.

Then check that this file actually exists: C:\\Users\\TUNUGU~1\\AppData\\Local\\Temp\\tmp4dwfnf5z (I copied it from your post). Run (still from the command line inside the virtual env) dot -Tps C:\\Users\\TUNUGU~1\\AppData\\Local\\Temp\\tmp4dwfnf5z
That should generate a lot of textual output, and no errors.

If any of the above fails I would advise reinstalling graphviz (with conda).

@Kiran-kkt

This comment has been minimized.

Copy link

@Kiran-kkt Kiran-kkt commented Mar 27, 2019

@onomatopeia Thank you very much for the help. I'll get back to you if I get it right.

@rajneeshaggarwal

This comment has been minimized.

Copy link

@rajneeshaggarwal rajneeshaggarwal commented Apr 13, 2019

It worked with the following command on windows 10:

conda install graphviz

@ifjgm005

This comment has been minimized.

Copy link

@ifjgm005 ifjgm005 commented May 13, 2019

I solved with this 2 steps on Linux

  1. conda install -c conda-forge graphviz
  2. restart jupyter notebook
    then ,it solved!
@xjzhou

This comment has been minimized.

Copy link

@xjzhou xjzhou commented May 14, 2019

@jbarrigapartarrieu make sure you have Graphviz installed separately on your system, not just in your project directory. You can find source and executable package installers here: https://www.graphviz.org/download/

in Ubuntu, I use 'apt-get install graphviz', then , it sovled.

@dalek7

This comment has been minimized.

Copy link

@dalek7 dalek7 commented Jun 6, 2019

@jbarrigapartarrieu make sure you have Graphviz installed separately on your system, not just in your project directory. You can find source and executable package installers here: https://www.graphviz.org/download/

in Ubuntu, I use 'apt-get install graphviz', then , it sovled.

This worked for me !

@mombo84

This comment has been minimized.

Copy link

@mombo84 mombo84 commented Nov 26, 2019

I had the same issue and the install of graphviz via Anaconda solved it for me on Windows 8.1.
I used this one:
conda install -c anaconda python-graphviz

I found it at the link below.
https://anaconda.org/anaconda/python-graphviz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
You can’t perform that action at this time.