InvocationException: GraphViz's executables not found


當我在visualize決策樹,運行以下代碼時,報錯: InvocationException: GraphViz's executables not found

import pydotplus
from io import StringIO
dot_data = StringIO()
tree.export_graphviz(clf, out_file=dot_data, feature_names=['age','sex','1st_class','2nd_class', '3rd_class'])
graph = pydotplus.graph_from_dot_data(dot_data.getvalue())
graph.write_png('titanic.png')
from IPython.core.display import Image
Image(filename='titanic.png')

查閱資料后發現,原來我沒有安裝GraphViz's executables.我是用pip安裝的Graphviz,但是Graphviz不是一個python tool,你仍然需要安裝GraphViz's executables.

problem solved:

You need to install the GraphViz package <http://www.graphviz.org/> so that graph.dag can invoke dot.

安裝完之后,再運行還是報錯:Exception: "dot.exe" not found in path.

那是因為你沒有將GraphViz安裝目錄的bin目錄放到環境變量的path路徑中,dot.exe在那個目錄下。

Note: As of version 2.31, the Visual Studio package no longer alters the PATH variable or accesses the registry at all. If you wish to use the command-line interface to Graphviz or are using some other program that calls a Graphviz program, you will need to set the PATH variable yourself.

設置完如果還是報同樣的錯誤,你需要重啟pyhon IDE.

REF.

[1]http://stackoverflow.com/questions/27666846/pydot-invocationexception-graphvizs-executables-not-found

[2]http://markmail.org/message/coebrty3itq426c2

[3]http://stackoverflow.com/questions/18438997/why-is-pydot-unable-to-find-graphvizs-executables-in-windows-8

[4]http://www.graphviz.org/Download_windows.php


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM