2

I have installed pydotplus and graphviz (I run Windows 10 and Python 3.6).

enter image description here

However, when I try to plot my Keras model I am getting an exception and I am asked to install pytdot and graphviz.

keras.utils.plot_model(model, 'my_first_model.png')

---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\pydot.py in create(self, prog, format, encoding)
   1914                 arguments=arguments,
-> 1915                 working_dir=tmp_dir,
   1916             )

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

C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\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, encoding, errors)
    708                                 errread, errwrite,
--> 709                                 restore_signals, start_new_session)
    710         except:

C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\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)
    996                                          os.fspath(cwd) if cwd is not None else None,
--> 997                                          startupinfo)
    998             finally:

FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

FileNotFoundError                         Traceback (most recent call last)
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\tensorflow\python\keras\utils\vis_utils.py in _check_pydot()
     44     # to check the pydot/graphviz installation.
---> 45     pydot.Dot.create(pydot.Dot())
     46   except Exception:

C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\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:

ImportError                               Traceback (most recent call last)
<ipython-input-58-f0e169c88003> in <module>()
----> 1 keras.utils.plot_model(model, 'my_first_model.png')

C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\tensorflow\python\keras\utils\vis_utils.py in plot_model(model, to_file, show_shapes, show_layer_names, rankdir)
    151       This enables in-line display of the model plots in notebooks.
    152   """
--> 153   dot = model_to_dot(model, show_shapes, show_layer_names, rankdir)
    154   _, extension = os.path.splitext(to_file)
    155   if not extension:

C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\tensorflow\python\keras\utils\vis_utils.py in model_to_dot(model, show_shapes, show_layer_names, rankdir)
     70   from tensorflow.python.util import nest
     71 
---> 72   _check_pydot()
     73   dot = pydot.Dot()
     74   dot.set('rankdir', rankdir)

C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\tensorflow\python\keras\utils\vis_utils.py in _check_pydot()
     47     # pydot raises a generic Exception here,
     48     # so no specific class can be caught.
---> 49     raise ImportError('Failed to import pydot. You must install pydot'
     50                       ' and graphviz for `pydotprint` to work.')
     51 

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

It is not clear why I am getting this error message. Since I have already installed the packages, what else is left to do?


graphviz has been downloaded

enter image description here

enter image description here

halfer
  • 19,824
  • 17
  • 99
  • 186
user8270077
  • 4,621
  • 17
  • 75
  • 140
  • Have you seen https://stackoverflow.com/a/36890526/349130 ? – Dr. Snoopy Sep 26 '19 at 11:41
  • I checked it. But I have downloaded graphviz and have added it to my System path. See my updated post. – user8270077 Sep 26 '19 at 18:42
  • Here is some advice that will be helpful. It is as much for readers considering helping as it is for you. (1) you are probably asking too many questions. Eight posts in two days means that you are not waiting for answers on one thing before jumping to the next thing. This would further indicate to me that you are not doing the necessary research. (2) You are adding chatty material about appreciating help, even though many editors have removed this from your prior posts. Technical writing is an expectation here. Meta references are available on request. – halfer Oct 09 '19 at 19:21

2 Answers2

0

https://stackoverflow.com/a/58498731/12138096

This solved the issue. just install them by conda instead of pip.

conda install pydot

conda install graphviz

Rintu
  • 1
  • 1
0

code: vis_utils.py

try:
  # pydot-ng is a fork of pydot that is better maintained.
  import pydot_ng as pydot
except ImportError:
  # pydotplus is an improved version of pydot
  try:
    import pydotplus as pydot
  except ImportError:
    # Fall back on pydot if necessary.
    try:
      import pydot
    except ImportError:
      pydot = None

code: pydot.py

def get_executable_extension():
    # type: () -> str
    if is_windows():
        return '.bat' if is_anacoda() else '.exe'
    else:
        return ''

If in a Anaconda env, please use

conda install pydot
conda install graphviz

If in a Python env, please use

pip install pydot

and make graphviz bin at you path.

bahuwang
  • 46
  • 3