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

在使用keras.utils.plot_model(model, “my_first_model_with_shape_info.png”, show_shapes=True)可视化模型的时候出现这个错误

系统Win10
tensorflow2.1(虚拟环境)

首先去官网下载并安装graphviz的msi文件地址如下:
https://graphviz.gitlab.io/_pages/Download/Download_windows.html

  1. 安装过程很简单:双击msi文件,然后一直next(记住安装路径,后面配置环境变量会用到路径信息)默认的安装目录在C:\Program Files (x86)\Graphviz2.38

  2. 配置环境变量
    将graphviz安装目录下的bin文件夹添加到Path环境变量中:
    Failed to import pydot. You must install pydot and graphviz for `pydotprint`
    验证安装成功:
    Failed to import pydot. You must install pydot and graphviz for `pydotprint`

  3. 在虚拟环境中安装graphviz(如我这里创建的虚拟环境名为tf2.1)
    Failed to import pydot. You must install pydot and graphviz for `pydotprint`

  4. 接下来在虚拟环境总安装pip install pydot。显示安装成功,但是运行keras.utils.plot_model(model, “my_first_model_with_shape_info.png”, show_shapes=True)还是报错。。这是因为pydot 停止更新,不适用于python3.6 以上版本了。卸载pip uninstall pydot,卸载,安装pydotplus
    pip uninstall pydot
    pip install pydotplus

  5. 安装成功后。将虚拟环境中对应目录下修改vis_utils.py 文件,将 pydot 全部替换为pydotplus
    Failed to import pydot. You must install pydot and graphviz for `pydotprint`

  6. 最后一步一定要重启计算机或者重启Anaconda再次运行成功