Pydot与Graphviz的安装(遇到的各种坑pydot failed to call graphviz)

Pydot与Graphviz的安装

(平台和环境:win10,Anaconda,pycharm)

step1. 安装 graphviz 包

pip install graphviz or conda install graphviz

step2. 安装 Graphviz 软件

直接到官网下载,D:\Program Files (x86)\Graphviz2.38\bin安装成功后把该目录下的 bin 文件夹添加到系统环境变量中。 在 cmd 中输入命令"dot -version"并按回车,若显示出 Graphviz 软件的版本信息,则安装成功。

step3. 安装 pydot 包

直接用pip安装pip install pydot 绘制模型时仍显示
pydot` failed to call GraphViz.Please install GraphViz (https://www.graphvi
大意是 pydot 找不到 graphviz。

求助网络发现安装步骤也没有任何问题,看到一篇文章说是pydot的锅。

pydot已经停止开发了,python3.5和python3.6已经用不起来。
对策是:
pip uninstall pydot
pip install pydotplus
然后找到keras里面的utils\vis_utils.py,把里面的pydot的都替换成pydotplus。

于是我就按照了pydotplus,并把D:\ProgramData\Anaconda3\Lib\site-packages\keras\utilsvis_utils.py下的pydotplus全部替换成pydotplus,这里应该时pydot安装包的一个升级。尝试了一波发现还是找不到graphviz。

那就尝试降低pydot的版本,安装1.1.0版本。
安装1.1.0版本的第二种办法是先安装 pyparsing 1.5.7版本。

>pip install pyparsing==1.5.7
>pip install pydot==1.1.0

失败!!

此处经历了九九八十一难后…
省略一万字…

找到 pydotplus 包的存储位置,将包名更改为pydot (会有两个文件包,pydotplus 和 pydotplus-2.0.2.dist-info , 只要修改前一个包名就可以了)。例如我的存储位置在D:\ProgramData\Anaconda3\Lib\site-packages\pydotplus , 修改为D:\ProgramData\Anaconda3\Lib\site-packages\pydot

再打开 pydot 文件夹中的 parser.py文件,将

import pydotplus 

修改为

import pydot

打开 pydot 文件夹中的 graphviz.py文件,找到 find_graphviz() 函数。将

#Method 3 (Windows only)

这行之后的代码替换为下列代码

# Method 3 (Windows only)
#
if os.sys.platform == 'win32':
    # Try and work out the equivalent of "C:\Program Files" on this
    # machine (might be on drive D:, or in a different language)
    #
    if False:  # os.environ.has_key('PROGRAMFILES'):
        # Note, we could also use the win32api to get this
        # information, but win32api may not be installed.
        path = os.path.join(os.environ['PROGRAMFILES'], 'ATT', 'GraphViz', 'bin')
    else:
        # Just in case, try the default...
        path = r"D:\Graphviz\bin"
    progs = __find_executables(path)
 
    if progs is not None:
        # print "Used default install location"
        return progs
 
for path in (
        '/usr/bin', '/usr/local/bin',
        '/opt/bin', '/sw/bin', '/usr/share',
        '/Applications/Graphviz.app/Contents/MacOS/'):
    progs = __find_executables(path)
 
    if progs is not None:
        # print "Used path"
        return progs
# Failed to find GraphViz
#
 
return None

到这里应该安装成功了,运行程序就能输出模型图了。
在这里插入图片描述
致谢 https://blog.csdn.net/fy_eng/article/details/81366723?utm_source=blogxgwz3

发布了145 篇原创文章 · 获赞 194 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/matafeiyanll/article/details/105482647