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') #调用修改后的函数,新增这行 ```

你可能感兴趣的:(keras,python)