问题
I installed pydotplus and graphviz in an virtual environment (Windows 8.1). Now I want to visualize a decision tree. However pydotplus is not able to find GraphViz's executables.
from sklearn import tree
from sklearn.datasets import load_iris
import pydotplus
from IPython.display import Image
iris = load_iris()
X,y = iris.data[:,2:], iris.target
clf = tree.DecisionTreeClassifier(max_depth=2)
clf.fit(X,y)
dot_data = tree.export_graphviz(clf,
out_file=None,
feature_names=iris.feature_names[2:],
class_names=iris.target_names,
rounded=True,
filled=True)
graph = pydotplus.graph_from_dot_data(dot_data)
Image(graph.create_png())
People solved this problem by adding the GraphViz bin directory their PATH. Apparently this directory usually is C:\Program Files (x86)\Graphviz2.34\bin\
. However it is not in my case. How can I find it?
回答1:
As I understood from comments, you've installed graphviz with pip. Thing is, that package named graphviz in pip is just a python interface for graphviz application. In other words, it's something similar to the pydotplus package that you try to get working.
What these packages do is give you few classes and methods for you to mess around in your Python code, and when it's time to render graph, they just call the graphviz binary and send it the generated dot source code. Of course, for them to work, you have to have the mentioned graphviz binary installed on your machine.
What you need to do is download and run graphviz installer (link for Windows), which is not connected with python and pip in any way. After installing it you will get your Graphviz folder in Program Files, with graphviz executables inside.
Probably you will need to add this folder to your PATH before working with pydotplus.
To check if everything's set up, run this command:
> dot -?
You should see the dot command manual page.
来源:https://stackoverflow.com/questions/56184153/graphvizs-executables-not-found-why-are-there-no-executables-installed-after