GraphViz 的可执行文件在 Anaconda 中找不到错误?

GraphViz's executables not found error in Anaconda?

我编写了以下代码来构建决策树,但出现以下错误。你能帮帮我吗?

       from sklearn.tree import DecisionTreeClassifier
       from sklearn.model_selection import train_test_split
       import pandas as pd
       import numpy as np
       from six import StringIO
       from sklearn.tree import export_graphviz
       from sklearn import tree
       import pydot
       from IPython.display import Image
       import pydotplus
       import graphviz
       
       
       dot_data = StringIO()
       export_graphviz(decisionTree1, out_file =dot_data, filled=True,
                       rounded =True, special_characters=True)
       graph = pydotplus.graph_from_dot_data(dot_data.getvalue())
       Image(graph.create_png())
  • 如果您正在使用 Linux,请在 cmd 中尝试此操作:sudo apt-get install graphviz
  • 如果使用 macOS,试试这个 brew install graphviz
  • i) 如果在 windows 上,通过 conda conda install graphviz 安装它并添加路径环境变量 C:\Users\username\Anaconda3\Library\bin\graphviz
  • ii) 尝试通过 conda install python-graphviz
  • 安装