NameError:全局名称'dot_parser'未定义 [英] NameError: global name 'dot_parser' is not defined

查看:169
本文介绍了NameError:全局名称'dot_parser'未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在玩决策树算法,试图绘制树图.但是,IDE报告了以下错误:

I was playing with the decision tree algorithm and trying to plot the tree. However the IDE reported following error:

Couldn't import dot_parser, loading of dot files will not be possible.
<class 'pandas.core.frame.DataFrame'>
    Traceback (most recent call last):
      File "C:/Users/s152730/Desktop/exe1.py", line 70, in <module>
        graph = pydot.graph_from_dot_data(test.getvalue())
      File "C:\Python27\lib\site-packages\pydot.py", line 220, in graph_from_dot_data
        return dot_parser.parse_dot_data(data)
    NameError: global name 'dot_parser' is not defined

我不知道如何处理此问题,因为我尝试卸载并重新安装pydot dan pyparsing,这是在其他答案中提出的,但没有帮助.

I have no idea how to deal with this problem because I've tried to uninstall and reinstall both pydot dan pyparsing, which was proposed in other answers, but it didn't help.

这是我的代码:

from sklearn.tree import DecisionTreeClassifier
from sklearn.tree import ExtraTreeClassifier
from sklearn import tree
from sklearn.externals.six import StringIO
import pydot
from IPython.display import Image

test = StringIO()
tree.export_graphviz(clf, out_file=test, feature_names = attribute_names)
graph = pydot.graph_from_dot_data(test.getvalue())
graph.writepng('test.png')
image(filename = 'test.png')

我正在使用python2.7并在PyCharm上运行,操作系统为win8.1. 感谢您的帮助.

I am using python2.7 and running on PyCharm, the OS is win8.1. Thanks for your help.

推荐答案

我刚刚将我的pydot更新为1.2.3,错误消失了.

I've just update my pydotto 1.2.3, and the error disappears.

sudo pip install -U pydot

这篇关于NameError:全局名称'dot_parser'未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆