1. 程式人生 > >import theano時報錯ImportError: No module named cPickle

import theano時報錯ImportError: No module named cPickle

>>> import theano
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/theano/__init__.py", line 52, in <module>
    from theano.gof import (
  File "/Library/Python/2.7/site-packages/theano/gof/__init__.py", line 38, in <module>
    from theano.gof.cc import \
  File "/Library/Python/2.7/site-packages/theano/gof/cc.py", line 25, in <module>
    from theano.gof import link
  File "/Library/Python/2.7/site-packages/theano/gof/link.py", line 18, in <module>
    from theano.gof.type import Type
  File "/Library/Python/2.7/site-packages/theano/gof/type.py", line 17, in <module>
    from theano.gof.op import CLinkerObject
  File "/Library/Python/2.7/site-packages/theano/gof/op.py", line 25, in <module>
    from theano.gof.cmodule import GCC_compiler
  File "/Library/Python/2.7/site-packages/theano/gof/cmodule.py", line 8, in <module>
    import six.moves.cPickle as pickle
ImportError: No module named cPickle

原因是:

theano要求six的版本在1.9.0以上,以前裝了低於該版本的six包。

解決方法:

1.在命令列中輸入:python,進入python的命令列模式;

2.依次輸入以下命令

import six
print six.__version__
print six.__file__

3.去import的目錄下刪除跟six有關的檔案:six.py  six.pyc

4.在命令列中輸入:sudo pip install six

done

如果還不行就在4之前再執行一次sudo pip uninstall six