windows下keras.utils.plot_model出现Failed to import pydot

1. 下载graphviz

从我的百度网盘上可以下载graphviz的zip或者msi文件。如果下载zip,直接解压并将相应的bin添加到环境变量中。

2. 使用pip安装pydot和graphviz

pip install pydot graphviz

3. 安装好之后发现还是报错FileNotFoundError: [WinError 2] “dot” not found in path

解决方法:找到pydot的源码,在pydot.py中找到类Dot

class Dot(Graph):
    """A container for handling a dot language file.

    This class implements methods to write and process
    a dot language file. It is a derived class of
    the base class 'Graph'.
    """



    def __init__(self, *argsl, **argsd):
        Graph.__init__(self, *argsl, **argsd)

        self.shape_files = list()
        self.formats = [
            'canon', 'cmap', 'cmapx',
            'cmapx_np', 'dia', 'dot',
            'fig', 'gd', 'gd2', 'gif',
            'hpgl', 'imap', 'imap_np', 'ismap',
            'jpe', 'jpeg', 'jpg', 'mif',
            'mp', 'pcl', 'pdf', 'pic', 'plain',
            'plain-ext', 'png', 'ps', 'ps2',
            'svg', 'svgz', 'vml', 'vmlz',
            'vrml', 'vtx', 'wbmp', 'xdot', 'xlib']

        self.prog = 'dot'

self.prog = ‘dot’ 改成 self.prog = 'dot.exe’

你可能感兴趣的:(tensorflow)