2013-05-22 43 views
0

我正在学习逻辑回归概念的概念。当我在python中实现它时,它显示了我下面提到的一些错误。我是python的初学者。有人能帮助纠正这个错误吗?Python RuntimeError:无法导入pydot

RuntimeError回溯(最近通话最后一个) 在()

64 theano.printing.pydotprint(predict, 
65       outfile="pics/logreg_pydotprint_predic.png", 
66       var_with_name_simple=True) 
67 # before compilation 
68 theano.printing.pydotprint_variables(prediction, 

C:\蟒蛇\ LIB \站点包\ theano \ printing.pyc在pydotprint(FCT,OUTFILE,结构紧凑,格式, with_ids,high_contrast,cond_highlight,colorCodes,max_label_size,scan_graphs,var_with_name_simple,print_output_file,assert_nb_all_strings)

565 
566  if not pydot_imported: 
567   raise RuntimeError("Failed to import pydot. You must install pydot" 
568        " for `pydotprint` to work.") 
569   return 

RuntimeError:无法导入pydot。您必须安装pydot for pydotprint才能工作。

+8

你有没有尝试安装pydot? –

回答

1

它主要取决于你把pydot文件放在哪里。如果您直接从Python Shell运行它,那么您应该将它们安装在模块文件夹中,该文件夹通常是主python文件夹中的“Lib”文件夹。

+0

我是初学者。我无法理解Lib文件夹的含义。我已经在python 2.7.3版本中运行了这个。在ipython中可以解释这个答案。 – subha

2

我得到了同样的错误,我做了以下序列,使其工作,在Python 3:根据您的操作系统类型从这里

source activate anaconda 
pip install pydot 
pip install pydotplus 
pip install pydot-ng 

然后你下载并安装的Graphviz: http://www.graphviz.org/Download..php

如果您在Anaconda上运行Python,请从终端打开Spyder,而不是从Anaconda打开。转到终端类型:

spyder 

然后:

import theano 
import theano.tensor as T 
. 
. 
. 
import pydot 
import graphviz 
import pydot_ng as pydot 

开发模型和:

theano.printing.pydotprint(prediction, outfile="/Volumes/Python/prediction.png", var_with_name_simple=True) 

你将有一个这样的画面: enter image description here