【问题标题】:How can I solve this Invocation Exception error?如何解决此调用异常错误?
【发布时间】:2021-08-04 16:18:27
【问题描述】:

当我在 jupyter notebook 上运行此代码时,它显示错误。我已经安装了 graphviz 并检查了它是否正确安装(通过此代码我试图获取决策树)。但是当我运行此代码时这么说,

InvocationException:程序以状态终止:1. 标准错误如下:'C:\Users\Dilki' 未被识别为内部或外部命令, 可运行的程序或批处理文件。

实际上这个路径是错误的。实际路径是'C:\Users\Dilki Thishaka'。我无法重命名文件夹名称(没有空格),因为这个文件夹是管理员文件夹。我该怎么做解决这个问题。请帮助..

#Generate the decision tree
from six import StringIO  
from IPython.display import Image  
from sklearn.tree import export_graphviz
import pydotplus
dot_data = StringIO()
tree = rnd_clf.estimators_[1] 
export_graphviz(tree, out_file=dot_data,feature_names = feature_list,rounded = True, precision = 1) 
 
graph = pydotplus.graph_from_dot_data(dot_data.getvalue())  
Image(graph.create_png())

Here is the code and the error

【问题讨论】:

  • 请编辑您的帖子以使用代码格式。即使您已经设法解决了问题(对您有好处!),更好的格式可能会帮助将来遇到同样问题的其他人。

标签: python jupyter-notebook random-forest decision-tree


【解决方案1】:

这是 Windows 上 pydot 的一个已知问题。

以下修复步骤来自此issue

1.在 env 中查找 dot.bat 文件。例如。在C:\Users\Ryan S\.conda\envs\week3\Library\bin\dot.bat

原始文件将包含

%~dp0.\graphviz\dot.exe %*

2。添加引号:

"%~dp0.\graphviz\dot.exe" %* 并保存

请随时查看上面链接的问题和this issue,了解更多信息。

编辑:寻找环境

你可以通过运行找到你的环境位置:

import sys
print(sys.prefix)

这将返回类似:C:\...\ENV_NAME.
那么dot.bat应该在C:\...\ENV_NAME\Library\bin\dot.bat

【讨论】:

  • 你能解释一下吗?我怎样才能找到这个dot.dat文件
  • @user12864747 我在答案中添加了关于dot.bat 应该在哪里的信息。
  • 成功了。非常感谢您的支持。
  • @user12864747 很高兴我能提供帮助。随意接受答案作为解决方案。这有助于其他有相同问题的用户快速找到解决方案。
猜你喜欢
  • 2022-01-03
  • 2018-12-06
  • 1970-01-01
  • 1970-01-01
  • 2020-06-23
  • 2013-06-07
  • 1970-01-01
  • 2012-01-12
  • 1970-01-01
相关资源
最近更新 更多