我想在我的 jupyter 笔记本中使用 graphviz 包。因此,我按照本指南安装它以在 JupyterNotebook Installing Python Packages from a Jupyter Notebook 中安装软件包:
import sys
!{sys.executable} -m pip install graphviz
!{sys.executable} -m pip install pydotplus
from sklearn.tree import export_graphviz
from six import StringIO
from IPython.display import Image
import pydotplus
Output:
Requirement already satisfied: graphviz in /opt/conda/lib/python3.8/site-packages (0.16)
Requirement already satisfied: pydotplus in /opt/conda/lib/python3.8/site-packages (2.0.2)
Requirement already satisfied: pyparsing>=2.0.1 in /opt/conda/lib/python3.8/site-packages (from pydotplus) (2.4.7)
执行此代码时出现错误“invocationException: GraphViz's executables not found”:
dot_data = StringIO()
export_graphviz(model,out_file=dot_data,filled=True,rounded=True,special_characters=True,feature_names = features,class_names=['0','1'])
graph = pydotplus.graph_from_dot_data(dot_data.getvalue())
graph.write_png('diabetes.png')
Image(graph.create_png())
Output:
...
/opt/conda/lib/python3.8/site-packages/pydotplus/graphviz.py in create(self,prog,format)
1957 self.progs = find_graphviz()
1958 if self.progs is None:
-> 1959 raise invocationException(
1960 'GraphViz\'s executables not found')
1961
对比graphviz的安装路径和执行代码时寻找的路径,好像没问题..
虽然检查过,如果“/opt/conda/lib/python3.8/site-packages”存在于PATH中:
import sys
sys.path
Output:
['/home/jovyan/work/Sales_Deal_Approval/data_preparation','/usr/local/spark/python','/usr/local/spark/python/lib/py4j-0.10.9-src.zip','/opt/conda/lib/python38.zip','/opt/conda/lib/python3.8','/opt/conda/lib/python3.8/lib-dynload','','/opt/conda/lib/python3.8/site-packages','/opt/conda/lib/python3.8/site-packages/IPython/extensions','/home/jovyan/.ipython']
我感觉我在错误的路径中安装了软件包.. 期待任何建议:)