GraphViz's executables not found解决方法

585 阅读1分钟

GraphViz's executables not found解决方法

今天在完成老师布置的作业时,遇到两个问题
ModuleNotFoundError: No module named ‘sklearn.externals.six‘
GraphViz's executables not found

老师的原题目是: image.png 我优化结果后:

image.png

image.png

先说说ModuleNotFoundError: No module named ‘sklearn.externals.six‘

image.png 系统找不到six这个模块,我用的是Anaconda3,当然第一步conda install six,当系统内部已经存在six这个模块的时候如果还出现报错问题,我用的方法是简单粗暴的使用from six import StringIO,问题得到解决。

第二个问题GraphViz's executables not found比较麻烦

首先是在Anaconda3中安装graphviz环境

conda install python-graphviz

在conda中安装了graphviz之后,在解释器中调用时仍然出现“GraphViz’s executables not found”报错。

查阅资料后发现,Graphviz不是一个python tool,需要在系统中安装GraphViz’s executables才可使用。

image.png

这个可以直接去官网下载,其他版本也可以
<https://graphviz.gitlab.io/_pages/Download/Download_windows.html>

安装完后在电脑PATH配置环境变量D:\Software\Graphviz\bin

(安装Graphviz的bin所在的路径)

将graphviz安装目录下的bin文件夹添加到Path环境变量中。

命令行dot -version,如果显示graphviz的相关版本信息,则安装配置成功。

若未成功添加,则Python中运行仍然出错:’ExecutableNotFound: failed to execute [‘dot’, ‘-Tpdf’, ‘-O’, ‘iris’], make sure the Graphviz executables are on your systems’ PATH‘

这个时候可能结果并没有解决

查阅资料后发现可用以下代码解决:

import os     

os.environ["PATH"] += os.pathsep + 'D:\Software\Graphviz\bin'

其中D:\Software\Graphviz\bin是安装Graphviz的bin所在的路径。

最后切记切记,需要重启IDE才能生效,或者直接重启电脑也可行。