windows python3库pydot运行出现:FileNotFoundError: [WinError 2] "dot" not found in path.

测试代码:

    from sklearn.datasets import load_iris
    from sklearn import tree
    iris = load_iris()
    clf = tree.DecisionTreeClassifier()
    clf = clf.fit(iris.data, iris.target)
    from sklearn.externals.six import StringIO
    import pydot
    dot_data = StringIO() 
    tree.export_graphviz(clf, out_file=dot_data)
    graph = pydot.graph_from_dot_data(dot_data.getvalue())
    graph[0].write_dot('iris_simple.dot')
    graph[0].write_png('iris_simple.png')

报错:

Traceback (most recent call last):
  File "C:\Users\78754\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\pydot.py", line 1914, in create
    working_dir=tmp_dir,
  File "C:\Users\78754\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\pydot.py", line 136, in call_graphviz
    **kwargs
  File "C:\Users\78754\AppData\Local\conda\conda\envs\tensorflow\lib\subprocess.py", line 676, in __init__
    restore_signals, start_new_session)
  File "C:\Users\78754\AppData\Local\conda\conda\envs\tensorflow\lib\subprocess.py", line 957, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] 系统找不到指定的文件。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\workspace python\ssd_py_server\src\test.py", line 437, in <module>
    DTtest()
  File "D:\workspace python\ssd_py_server\src\test.py", line 435, in DTtest
    graph[0].write_png('iris_simple.png')
  File "C:\Users\78754\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\pydot.py", line 1734, in new_method
    encoding=encoding)
  File "C:\Users\78754\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\pydot.py", line 1817, in write
    s = self.create(prog, format, encoding=encoding)
  File "C:\Users\78754\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\pydot.py", line 1921, in create
    raise OSError(*args)
FileNotFoundError: [WinError 2] "dot" not found in path.

解决办法:

安装软件:graphviz-2.38.msi

配置环境变量:

测试之后还是报错,后来发现,错误提示是找不到“dot”程序,而不是"dot.exe"程序,这就好办了,找到pydot的源码,在pydot.py中找到类Dot
 

 

修改self.prog = 'dot'为self.prog = 'dot.exe',之后测试,成功运行例子

  • 23
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 28
    评论
评论 28
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值