首页 > Web开发 > 详细

【避坑解决】OSError: `pydot` failed to call GraphViz.Please install GraphViz (https://www.graphviz.org/) and ensure that its executables are in the $PATH. 解决办法

时间:2020-04-04 00:08:31      阅读:400      评论:0      收藏:0      [点我收藏+]

今天想用keras中的plot_model输出网络结构图,但是却出现了这个错误,看了网上的一些解决方法,记录下来。

一、常规操作是:(我的解决方案直接看第二部分)

1、使用pip命令安装这两项内容

pip install pydot
pip install graphviz

2、windows下紧接着下载graphviz-2.38.msi进行安装(https://www.softpedia.com/get/Others/Miscellaneous/Graphviz.shtml),linux、mac应该有类似的安装方法。

3、将’C:/Program Files (x86)/Graphviz2.38/bin/‘添加进环境的Path

   如何添加环境变量就不截图了(https://baijiahao.baidu.com/s?id=1652502091402613426&wfr=spider&for=pc

理论上这个时候应该这个时候就好用了,但是仍然会出现相同或者其他错误,其实感觉最主要的原因应该就是plot_model中,使用的pydot已经不再更新了,应该使用其他进行替代,好像应该是在keras中没有更新,但是在tensorflow中其实已经更新。

二、我尝试的方法

1、找到keras下的vis_utils.py进行修改,我的在C:\Users\Harry\.conda\envs\my-keras\Lib\site-packages\keras\utils

根据自己的情况查找(强烈安利Everyting,一键检索)

try:
    import pydot
except ImportError:
    pydot = None

替换为

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

2、与第一部分一致,复制过来稍作修改。

①、使用pip命令安装这两项内容

pip install pydot_ng
pip install graphviz

、windows下紧接着下载graphviz-2.38.msi进行安装(https://www.softpedia.com/get/Others/Miscellaneous/Graphviz.shtml),linux、mac应该有类似的安装方法。

③、将’C:/Program Files (x86)/Graphviz2.38/bin/‘添加进环境的Path

   如何添加环境变量就不截图了(https://baijiahao.baidu.com/s?id=1652502091402613426&wfr=spider&for=pc

3、在程序开头添加

import os
os.environ["PATH"] += os.pathsep + C:/Program Files (x86)/Graphviz2.38/bin/

应该这样就可以使用了

plot_model(model, to_file="1.png", show_shapes=True)

【避坑解决】OSError: `pydot` failed to call GraphViz.Please install GraphViz (https://www.graphviz.org/) and ensure that its executables are in the $PATH. 解决办法

原文:https://www.cnblogs.com/wanghairui/p/12629669.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!