10

I'm using python 3.6.3 on a windows 10 machine. I installed pydot and graphviz using pip install via:

    py -m pip install pydot
    py -m pip install graphviz

I also went to the graphviz website and downloaded and installed the windows version here: http://www.graphviz.org/Download_windows.php which default installed to program files(x86). But when I go to plot my model in keras, I still get the error saying I have to install pydot and graphviz and that the import failed. I can do

    import pydot
    import graphviz

on my python console just fine, they throw no errors. What else should I do to be able to graph my neural net?

enumaris
  • 1,868
  • 1
  • 16
  • 34
  • Try: `py -m pip3 install pydot py -m pip3 install graphviz` – Marcin Możejko Nov 08 '17 at 21:20
  • I don't have pip3. But usually if I just use "py -m pip" that's already for python 3 cus to get to python 2 I have to do py -2.7 -m pip install...etc. Also, I tested the import statements with python 3 and it works. – enumaris Nov 09 '17 at 00:17

4 Answers4

11

The path(s) to the installed GraphViz executables (dot, neato, etc.) need to be in the PATH environment variable, in order for pydot to find them. pydot used to search for those executables in earlier versions, but not any more.

Also:

  1. pydot is a Python package.
  2. GraphViz is a collection of tools written in C for computing graph layouts
  3. graphviz is a Python package entirely unrelated to pydot. These two Python packages do not interact in any way with each other. Installing one of them should suffice (together with GraphViz).

See also:

and links from there.

0 _
  • 10,524
  • 11
  • 77
  • 109
  • So does that mean I have to go into the source code of pydot and manually add the path to graphviz? – enumaris Nov 10 '17 at 05:14
  • I figured it out, sorry, I've never made edits to my windows PATH variable before. – enumaris Nov 10 '17 at 05:30
  • In case that the user calls `pydot` directly (not via `keras` or other intermediary), then a middle solution is to pass the path via the `prog` argument of the `Dot.write_*` or `Dot.create_*` methods (see [this docstring](https://github.com/erocarrera/pydot/blob/35a8d858bd9da0b37268fe9b317fe4895387e75f/pydot.py#L1834)). However, this solution is discouraged. Better to set an environment configuration, and copy it when reinstalling the OS. In *nix systems this is usually done in `~/.bashrc` (I recommend committing this configuration file to a `git` repository). – 0 _ Nov 10 '17 at 05:51
  • 1
    Have a look over this answer with complete procedure -> https://stackoverflow.com/a/50025414/6126603 – sync11 Apr 25 '18 at 15:01
  • @dataLeo `keras >= 2.1.6` has been updated to recent versions of `pydot`: https://github.com/keras-team/keras/pull/9904 – 0 _ Apr 25 '18 at 19:51
  • @loannis Thanks for the response. My answer targeted keras version 2.1.5 – sync11 Apr 26 '18 at 04:31
2

Complementing @Ioannis answer, you have to install GraphViz executables via conda (conda install GraphViz).

For my case, after installing GraphViz I tried with the latest pydot (pip install pydot) and the error was resolved.

1

Just to complete the @dataLeo 's solution, Python 3 users can use pydotplus package instead of pydot-ng package. To summarize:

  1. install pydot+graphviz and pydotplus by commands "conda install pydot" and "conda install -c conda-forge pydotplus".
  2. Go to the vis_utils.py file and change line 11 from import pydot to import pydotplus as pydot.

PS: You can locate the vis_utils.py file by checking help for plot_model command in ipython console, i.e. after from keras.utils import plot_model, type ??plot_model in ipython console.

Tested on Windows 10-64 bit with Anaconda python-3.6

tu_curious
  • 387
  • 4
  • 13
1

I solved this problem by installing the packages with :

conda install graphviz
conda install pydot
conda install pydotplus
Baya Lina
  • 457
  • 4
  • 11