Tag Archives: graphviz

[Keras] ImportError: Failed to import pydot. You must install pydot and graphviz for `pydotprint` to

problem description

what happened was, when I was happily building a model with Keras, I found that there was an official function for drawing the model plot_model(), so I happily called the function keras.utils.plot_model(model, 'model.png', show_shapes=True), and the result was the following error:

InvocationException: GraphViz's executables not found
...
ImportError: Failed to import pydot. You must install pydot and graphviz for `pydotprint` to work.

I thought, was it because I didn’t install , pydot and graphviz?So I happily turned on PyCharm and loaded my virtual environment with pydot and graphviz, but it was still reporting an error.

then I shut myself up for a while. After I closed myself up, I went to baidu and Google to find a solution. Sure enough, many people met the same problem as me. According to the big guy [1], this is an environmental problem, the solution is to PIP install graphviz or something, or manually download the graphviz installation package on the official website, and then add the system environment variable Path, such as C:\Program Files (x86)\Graphviz2.38\bin something.

I thought this solution made sense, and I happily tried it out, and still got an error.

and then I shut myself down again and went back to looking for a solution. Some people [2] say that the order of installation is very important. First install pydot, then install graphviz; Someone [3] said to use keras.utils.vis_utils.plot_model instead of keras.utils.plot_model. In short, the feeling is not reliable.

finally, you guessed it, I uninstalled PyCharm and pydot in pydot ( PIP install pydot0) in PyCharm and pydot) in the pydot). Success!

then I thought about what was causing the error for a while, I tried to delete the system variable of graphviz, but the error didn’t occur. Oh, calculate, calculate, just work!

environment

  • Windows 10
  • Python 3.6
  • TensorFlow 2.0 Beta (built-in Keras)

effect

Reference

  1. Rob. (August 25, 2018). Graphviz and Pydotplus not working. Retrieved from https://datascience.stackexchange.com/questions/37428/graphviz-and-pydotplus-not-working
  2. web_ninja. (August 26, 13). Why is pydot unable to find GraphViz’s Executables in Windows 8?Retrieved from https://stackoverflow.com/questions/18438997/why-is-pydot-unable-to-find-graphvizs-executables-in-windows-8
  3. XifengGuo. (November, 6, 2017). pydot issue. Retrieved from https://github.com/XifengGuo/CapsNet-Keras/issues/7

ExecutableNotFound: failed to execute [‘dot’, ‘-Tsvg’], make sure the Graphviz executables are on yo

problem occurs

has a problem drawing using the built-in features of xgboost

ExecutableNotFound: failed to execute ['dot', '-Tsvg'], make sure the Graphviz executables are on your systems' PATH

looking for reasons

reason: graphviz itself was software, needed an extra download, and added its bin to the environment variable.

solution

download kit

Ubuntu can directly sudo apt install graphviz. If not, please go to graphviz’s official website to download or you can directly click this link to ubuntu to search graphviz package

environment dependencies refer to — several solutions for installing dependencies under Ubuntu

view file details (Windows, Linux common command)

after downloading, use dot-verison command to query the bin folder address,

at the white bar in the figure
Add the environment variable in Ubuntu

then add the environment variable, source /etc/profile to make it take effect.

export PATH=$PATH:/usr/lib/x86_64-linux-gnu/graphviz

at this point the error is resolved and you can continue running the xgboost code.

Installation and use of graphviz under mac

1. Install
Graphviz http://www.graphviz.org/
MAC users recommend to install directly with homebrew, the official version is older

1. Install homebrew
open the terminal to copy and paste the following command:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

After homebrew is installed, run brew install Graphviz to

Brew: command not found
= bash: brew: command not found

terminal input sudo vim.bash_profile ,
input I to enter the input mode,
add export PATH="/usr/local/bin:$PATH",
press esc to exit the input mode,
enter :wq to exit and save
finally enter source.bash_profile to make the configuration take effect.
(note that : and Spaces are also entered, bash_profile may be saved with a warning, :w! force can be saved, more vim command reference http://www.cnblogs.com/usergaojie/p/4583796.html)

2. Use
for a random example:
1. Use the text editor (sublime in this case) to type the following:

digraph pic { 
  Hello -> World
}

3. Open the terminal and switch to the directory where the dot file is located, enter dot pic.dot-t png-o pic.png
4. You can see that a pic.png file

has been generated under the dot file directory

>
>
>
>
>
>
>
>
>
>
>
>
https://blog.zengrong.net/post/2294.html
https://zhuanlan.zhihu.com/p/22820399