1

使用 theano.printing.pydotprint() 函数时出现错误

以下几行工作正常,没有任何错误:

>>> from theano import *
>>> import theano.tensor as T
>>> import pydot
>>> import numpy

当我跑步时

>>> theano.printing.pydotprint

在 python 解释器中,我得到的输出为

<function pydotprint at 0x307ed70>

但问题是当我使用函数执行脚本时出现以下错误

RuntimeError: Failed to import pydot. You must install pydot for `pydotprint` to work.

知道有什么问题吗?

PS:我正在运行这里给出的python教程:http: //deeplearning.net/software/theano/tutorial/printing_drawing.html 所以对函数的调用肯定是正确的。

这是我得到的错误的回溯:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
/usr/lib/python2.7/dist-packages/IPython/utils/py3compat.pyc in execfile(fname, *where)
    173             else:
    174                 filename = fname
--> 175             __builtin__.execfile(filename, *where)

/home/abhishek/Desktop/Theano/test2.py in <module>()
     64 if not os.path.exists('pics'):
     65     os.mkdir('pics')
---> 66 theano.printing.pydotprint(predict,outfile="pics/logreg_pydotprint_predic.png",var_with_name_simple=True)
     67 # before compilation

     68 theano.printing.pydotprint_variables(prediction,outfile="pics/logreg_pydotprint_prediction.png",var_with_name_simple=True)

/usr/local/lib/python2.7/dist-packages/theano/printing.pyc in pydotprint(fct, outfile, compact, format, with_ids, high_contrast, cond_highlight, colorCodes, max_label_size, scan_graphs, var_with_name_simple, print_output_file, assert_nb_all_strings)
    566 
    567     if not pydot_imported:
--> 568         raise RuntimeError("Failed to import pydot. You must install pydot"
    569                             " for `pydotprint` to work.")
    570         return

RuntimeError: Failed to import pydot. You must install pydot for `pydotprint` to work.
4

2 回答 2

4

尝试按照此问题的解决方案重新安装 pydot ,但这不起作用。

那是

pip uninstall pyparsing
pip install -Iv https://pypi.python.org/packages/source/p/pyparsing/pyparsing-1.5.7.tar.gz#md5=9be0fcdcc595199c646ab317c1d9a709
pip install pydot

此安装存在一些问题,即使每次都给出安装成功的消息。

sudo apt-get install python-pydot

这行得通。

“因为解决方案不是从某个地方安装 pydot,而是从官方 ubuntu 存储库安装“python-pydot”。” -萨迪克的回答奏效了

我们必须注意,在成功安装 pydot 后,可以在两个地方进行检查。
/usr/share/doc/python-pydot

/usr/share/python-support/python-pydot

在此处输入图像描述

于 2014-08-21T12:21:16.510 回答
1

Abhishek:检查您是否可以在 lib 文件夹下看到“pydot”文件夹。看起来你在ix机器上。理想情况下,您会发现它是否安装在“lib”文件夹/或站点包中。

同时,我建议您尝试重新安装包(pydot),看看它是否有帮助。

于 2014-08-21T11:16:27.173 回答