OSError: `pydot` failed to call GraphViz.Please install GraphViz问题解决

在keras可视化模型输出时,往往用:
from keras.utils import plot_model
plot_model(model, to_file=‘model.png’)

在此前,下面的操作是必须的
1.pip3 install pydot
2.pip3 install graphviz
3.Windows 安装 graphviz-2.38.msi
4.将’C:/Program Files (x86)/Graphviz2.38/bin/'添加进环境的Path,如知乎专栏所述。
5.步骤4功能同在代码中添加:

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

如果还是弹出问题:OSError: pydot failed to call GraphViz.Please install GraphViz (https://www.http?/graphviz.org/) and ensure that its executables are in the $PATH.

第一、尝试pip3 install pydot_ng (不是必须的)
import pydot_ng as pydot
print (pydot.find_graphviz())
可以解决部分问题。如还是报错,用下面方案。

第二、按chutongz大神博客更改pydot.py的代码。
1.修改set_prog函数:

    def set_prog(self, prog):
        """Sets the default program.

        Sets the default program in charge of processing
        the dot file into a graph.
        """
	self.prog = prog

为如下样子:

def set_prog(self, prog):
        """Sets the default program.
        Sets the default program in charge of processing
        the dot file into a graph.
        """
        path = r'path/to/your/dot/exe/file'# 例如我的:C:/Program Files (x86)/Graphviz2.38/bin/
        prog  = os.path.join(path, prog)
        prog += '.exe'
        #self.prog = prog
        return prog

2.修改create函数

if prog is None:
            prog = self.prog
        assert prog is not None
        prog = self.set_prog('dot') #调用修改后的函数,新增这行 ```
  • 19
    点赞
  • 40
    收藏
    觉得还不错? 一键收藏
  • 11
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值