问题描述
在使用 keras 的plot_model 函数时,需要安装 pydot,但是当我 “pip install pydot” 后运行程序时,程序报出如下错误:
OSError: pydot
failed to call GraphViz.Please install GraphViz (https://www.graphviz.org/) 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.
在经过多次试验后,得出如下解决方案,希望对大家有所帮助,少走弯路!
解决方案
环境:Windows 7 64位
编译器:Anaconda3, Spyder (tensorflow)
1、打开 GraphViz 官网
官网地址: GraphViz
官网界面:
2、下载 GraphViz
(1)、在官网首页下拉,找到 Download,点击 Download:
(2)、进入下载界面,找到 Windows,点击 “Stable 2.38 Windows install packages”:
(3)、进入 Windows Packages 下载界面, 点击 “graphviz-2.38.msi” 下载:
(4)、双击默认安装即可。
注意:
(1)、安装成功后,将路径 “C:\Program Files (x86)\Graphviz2.38\bin” 添加到环境变量!!!
(2)、最好能重启变脑!!!
3、安装 pygraphViz 和 pydot
打开 Anaconda Prompt,激活 tensorflow,使用 pip 安装:
# 第一步,然后回车
activate tensorflow
# 第二步,然后回车
pip install graphViz
# 第三步,然后回车
pip install pydot==1.2.4
本人安装的 graphViz 的版本默认是0.10.1,如果 pydot 的版本不是 1.2.4 的话,可能依然会报错。
4、运行成功
from keras.utils import plot_model
plot_model(model, to_file='*.png')
运行成功,会在当前文件夹下生成模型的拓扑图。
如果依然报错,请重启电脑!!!重启电脑可解决 80% 的问题!!!
祝您浏览愉快!