GraphViz's executables not found - Why are there no executables installed after installation of graphViz via pip?

社会主义新天地 提交于 2019-12-24 06:35:37

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!