我是靠谱客的博主 火星上哑铃,最近开发中收集的这篇文章主要介绍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:Users78754AppDataLocalcondacondaenvstensorflowlibsite-packagespydot.py", line 1914, in create
    working_dir=tmp_dir,
  File "C:Users78754AppDataLocalcondacondaenvstensorflowlibsite-packagespydot.py", line 136, in call_graphviz
    **kwargs
  File "C:Users78754AppDataLocalcondacondaenvstensorflowlibsubprocess.py", line 676, in __init__
    restore_signals, start_new_session)
  File "C:Users78754AppDataLocalcondacondaenvstensorflowlibsubprocess.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 pythonssd_py_serversrctest.py", line 437, in <module>
    DTtest()
  File "D:workspace pythonssd_py_serversrctest.py", line 435, in DTtest
    graph[0].write_png('iris_simple.png')
  File "C:Users78754AppDataLocalcondacondaenvstensorflowlibsite-packagespydot.py", line 1734, in new_method
    encoding=encoding)
  File "C:Users78754AppDataLocalcondacondaenvstensorflowlibsite-packagespydot.py", line 1817, in write
    s = self.create(prog, format, encoding=encoding)
  File "C:Users78754AppDataLocalcondacondaenvstensorflowlibsite-packagespydot.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',之后测试,成功运行例子

最后

以上就是火星上哑铃为你收集整理的windows python3库pydot运行出现:FileNotFoundError: [WinError 2] "dot" not found in path.的全部内容,希望文章能够帮你解决windows python3库pydot运行出现:FileNotFoundError: [WinError 2] "dot" not found in path.所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(80)

评论列表共有 0 条评论

立即
投稿
返回
顶部