Theano:AttributeError:模块'theano'没有属性'gof'

时间:2017-05-22 00:55:25

标签: deep-learning theano python-3.6

此主题中提供的解决方案对我不起作用:

Import theano gives the AttributeError: module 'theano' has no attribute 'gof'

我已经尝试了conda install theano(对于jupyter笔记本)并且尽管安装完美但我仍然遇到上述错误。

我正在使用带有Nvidia 1070 GPU的Python 3.6,Windows 7,Anaconda / Jupyter笔记本。 Theano是版本.9.0

回溯如下:

ImportError                               Traceback (most recent call last)
C:\Users\Moondra\AppData\Local\Programs\Python\Python36\lib\site-packages\theano\gof\lazylinker_c.py in <module>()
     74         if version != getattr(lazylinker_ext, '_version', None):
---> 75             raise ImportError()
     76 except ImportError:

ImportError: 

During handling of the above exception, another exception occurred:

ImportError                               Traceback (most recent call last)
C:\Users\Moondra\AppData\Local\Programs\Python\Python36\lib\site-packages\theano\gof\lazylinker_c.py in <module>()
     91             if version != getattr(lazylinker_ext, '_version', None):
---> 92                 raise ImportError()
     93         except ImportError:

ImportError: 

During handling of the above exception, another exception occurred:

Exception                                 Traceback (most recent call last)
C:\Users\Moondra\AppData\Local\Programs\Python\Python36\lib\site-packages\theano\gof\vm.py in <module>()
    661         raise theano.gof.cmodule.MissingGXX('lazylinker will not be imported if theano.config.cxx is not set.')
--> 662     from . import lazylinker_c
    663 

C:\Users\Moondra\AppData\Local\Programs\Python\Python36\lib\site-packages\theano\gof\lazylinker_c.py in <module>()
    126             cmodule.GCC_compiler.compile_str(dirname, code, location=loc,
--> 127                                              preargs=args)
    128             # Save version into the __init__.py file.

C:\Users\Moondra\AppData\Local\Programs\Python\Python36\lib\site-packages\theano\gof\cmodule.py in compile_str(module_name, src_code, location, include_dirs, lib_dirs, libs, preargs, py_module, hide_symbols)
   2315             raise Exception('Compilation failed (return status=%s): %s' %
-> 2316                             (status, compile_stderr.replace('\n', '. ')))
   2317         elif config.cmodule.compilation_warning and compile_stderr:

Exception: Compilation failed (return status=1): In file included from C:\Users\Moondra\AppData\Local\Programs\Python\Python36\include/Python.h:50:0,.                  from C:\Users\Moondra\AppData\Local\Theano\compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_94_Stepping_3_GenuineIntel-3.6.0-64\lazylinker_ext\mod.cpp:1:. C:\Users\Moondra\AppData\Local\Programs\Python\Python36\include/pyport.h:686:2: error: #error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?).".  #error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?).".   ^. In file included from C:\Users\Moondra\AppData\Local\Programs\Python\Python36\include/Python.h:133:0,.                  from C:\Users\Moondra\AppData\Local\Theano\compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_94_Stepping_3_GenuineIntel-3.6.0-64\lazylinker_ext\mod.cpp:1:. C:\Users\Moondra\AppData\Local\Programs\Python\Python36\include/fileutils.h:23:5: error: '__int64' does not name a type.      __int64 st_ino;.      ^. C:\Users\Moondra\AppData\Local\Programs\Python\Python36\include/fileutils.h:29:5: error: '__int64' does not name a type.      __int64 st_size;.      ^. In file included from /usr/include/sys/stat.h:22:0,.                  from C:\Users\Moondra\AppData\Local\Programs\Python\Python36\include/pyport.h:227,.                  from C:\Users\Moondra\AppData\Local\Programs\Python\Python36\include/Python.h:50,.                  from C:\Users\Moondra\AppData\Local\Theano\compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_94_Stepping_3_GenuineIntel-3.6.0-64\lazylinker_ext\mod.cpp:1:. C:\Users\Moondra\AppData\Local\Programs\Python\Python36\include/fileutils.h:30:12: error: expected ';' at end of member declaration.      time_t st_atime;.             ^. C:\Users\Moondra\AppData\Local\Programs\Python\Python36\include/fileutils.h:30:12: error: expected unqualified-id before '.' token.      time_t st_atime;.             ^. C:\Users\Moondra\AppData\Local\Programs\Python\Python36\include/fileutils.h:32:12: error: expected ';' at end of member declaration.      time_t st_mtime;.             ^. C:\Users\Moondra\AppData\Local\Programs\Python\Python36\include/fileutils.h:32:12: error: expected unqualified-id before '.' token.      time_t st_mtime;.             ^. C:\Users\Moondra\AppData\Local\Programs\Python\Python36\include/fileutils.h:34:12: error: expected ';' at end of member declaration.      time_t st_ctime;.             ^. C:\Users\Moondra\AppData\Local\Programs\Python\Python36\include/fileutils.h:34:12: error: expected unqualified-id before '.' token.      time_t st_ctime;.             ^. In file included from C:\Users\Moondra\AppData\Local\Programs\Python\Python36\include/Python.h:8:0,.                  from C:\Users\Moondra\AppData\Local\Theano\compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_94_Stepping_3_GenuineIntel-3.6.0-64\lazylinker_ext\mod.cpp:1:. C:\Users\Moondra\AppData\Local\Programs\Python\Python36\include/pyconfig.h:269:23: error: '__int64' does not name a type.  # define PY_LONG_LONG __int64.                        ^. C:\Users\Moondra\AppData\Local\Programs\Python\Python36\lib\site-packages\numpy\core\include/numpy/npy_common.h:309:9: note: in expansion of macro 'PY_LONG_LONG'.  typedef PY_LONG_LONG npy_longlong;.          ^. In file included from C:\Users\Moondra\AppData\Local\Programs\Python\Python36\lib\site-packages\numpy\core\include/numpy/npy_3kcompat.h:22:0,.                  from C:\Users\Moondra\AppData\Local\Theano\compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_94_Stepping_3_GenuineIntel-3.6.0-64\lazylinker_ext\mod.cpp:7:. C:\Users\Moondra\AppData\Local\Programs\Python\Python36\lib\site-packages\numpy\core\include/numpy/npy_common.h:310:31: error: expected initializer before 'npy_ulonglong'.  typedef unsigned PY_LONG_LONG npy_ulonglong;.                                ^. In file included from C:\Users\Moondra\AppData\Local\Programs\Python\Python36\lib\site-packages\numpy\core\include/numpy/npy_3kcompat.h:22:0,.                  from C:\Users\Moondra\AppData\Local\Theano\compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_94_Stepping_3_GenuineIntel-3.6.0-64\lazylinker_ext\mod.cpp:7:. C:\Users\Moondra\AppData\Local\Programs\Python\Python36\lib\site-packages\numpy\core\include/numpy/npy_common.h:611:17: error: 'npy_longlong' does not name a type.          typedef npy_longlong npy_int64;.                  ^. C:\Users\Moondra\AppData\Local\Programs\Python\Python36\lib\site-packages\numpy\core\include/numpy/npy_common.h:612:17: error: 'npy_ulonglong' does not name a type.          typedef npy_ulonglong npy_uint64;.                  ^. C:\Users\Moondra\AppData\Local\Programs\Python\Python36\lib\site-packages\numpy\core\include/numpy/npy_common.h:1090:9: error: 'npy_int64' does not name a type.  typedef npy_int64 npy_timedelta;.          ^. C:\Users\Moondra\AppData\Local\Programs\Python\Python36\lib\site-packages\numpy\core\include/numpy/npy_common.h:1091:9: error: 'npy_int64' does not name a type.  typedef npy_int64 npy_datetime;.          ^. In file included from C:\Users\Moondra\AppData\Local\Programs\Python\Python36\lib\site-packages\numpy\core\include/numpy/ndarrayobject.h:18:0,.                  from C:\Users\Moondra\AppData\Local\Programs\Python\Python36\lib\site-packages\numpy\core\include/numpy/npy_3kcompat.h:23,.                  from C:\Users\Moondra\AppData\Local\Theano\compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_94_Stepping_3_GenuineIntel-3.6.0-64\lazylinker_ext\mod.cpp:7:. C:\Users\Moondra\AppData\Local\Programs\Python\Python36\lib\site-packages\numpy\core\include/numpy/ndarraytypes.h:742:9: error: 'npy_int64' does not name a type.          npy_int64 year;.          ^. C:\Users\Moondra\AppData\Local\Programs\Python\Python36\lib\site-packages\numpy\core\include/numpy/ndarraytypes.h:748:9: error: 'npy_int64' does not name a type.          npy_int64 day;.          ^. In file included from C:\Users\Moondra\AppData\Local\Theano\compiledir_Windows-7-6.1.7601-SP1-Intel64_Family_6_Model_94_Stepping_3_GenuineIntel-3.6.0-64\lazylinker_ext\mod.cpp:7:0:. C:\Users\Moondra\AppData\Local\Programs\Python\Python36\lib\site-packages\numpy\core\include/numpy/npy_3kcompat.h: In function 'int npy_PyFile_DupClose2(PyObject*, FILE*, off_t)':. C:\Users\Moondra\AppData\Local\Programs\Python\Python36\lib\site-packages\numpy\core\include/numpy/npy_3kcompat.h:274:41: error: 'lseek' was not declared in this scope.      if (npy_lseek(fd, orig_pos, SEEK_SET) == -1) {.                                          ^. 

During handling of the above exception, another exception occurred:

AttributeError                            Traceback (most recent call last)
<ipython-input-6-3397704bd624> in <module>()
----> 1 import theano

C:\Users\Moondra\AppData\Local\Programs\Python\Python36\lib\site-packages\theano\__init__.py in <module>()
     64     object2, utils)
     65 
---> 66 from theano.compile import (
     67     SymbolicInput, In,
     68     SymbolicOutput, Out,

C:\Users\Moondra\AppData\Local\Programs\Python\Python36\lib\site-packages\theano\compile\__init__.py in <module>()
      8         SpecifyShape, specify_shape, register_specify_shape_c_code)
      9 
---> 10 from theano.compile.function_module import *
     11 
     12 from theano.compile.mode import *

C:\Users\Moondra\AppData\Local\Programs\Python\Python36\lib\site-packages\theano\compile\function_module.py in <module>()
     19 from theano.compat import izip
     20 from theano.gof import graph
---> 21 import theano.compile.mode
     22 import theano.compile.profiling
     23 from theano.compile.io import (

C:\Users\Moondra\AppData\Local\Programs\Python\Python36\lib\site-packages\theano\compile\mode.py in <module>()
      8 import theano
      9 from theano import gof
---> 10 import theano.gof.vm
     11 from theano.configparser import config
     12 from theano.compile.ops import _output_guard

C:\Users\Moondra\AppData\Local\Programs\Python\Python36\lib\site-packages\theano\gof\vm.py in <module>()
    669 except ImportError:
    670     pass
--> 671 except (OSError, theano.gof.cmodule.MissingGXX) as e:
    672     # OSError happens when g++ is not installed.  In that case, we
    673     # already changed the default linker to something else then CVM.

AttributeError: module 'theano' has no attribute 'gof'

更新:

我使用pip3.6和conda(我有两个版本)卸载了theano然后重新安装了 conda install theano

现在我收到了这个错误:

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-6-3397704bd624> in <module>()
----> 1 import theano

ModuleNotFoundError: No module named 'theano'

尝试重新启动Jupyter笔记本,获取No module named 'theano'

编辑: 重新安装了theano几次。我甚至重新启动了我的电脑。 还有这个问题。

我在anaconda文件夹中的theano文件夹中看到site-packages。 所以不要了解问题所在。

问题又回到了:

AttributeError: module 'theano' has no attribute 'gof'

谢谢。

3 个答案:

答案 0 :(得分:1)

对我来说,这是一个numpy版本问题。一旦我将我的numpy重新安装到版本1.13.1,它就有效了。

注意:确保以兼容的方式更新依赖于numpy的其他软件包,例如Scikit-learn等。最好的方法是创建一个仅用于深度学习的环境。

答案 1 :(得分:1)

对我来说,这是一个编译器问题,是由于用于编译的错误(意外)g++版本所致。

m2w64-toolchain包(其中包含一个g++编译器&#34; 强烈推荐&#34;与theano一起使用时,cf。{ {3}}),我安装了一个cygwin实例,其g++.exe指向了windows系统的PATH变量。在import theano期间,使用了cygwin版本而不是m2w64-toolchain版本。

另见我在这里找到解决方案的讨论:http://www.usp.br/nereus/?dados=brasil

答案 2 :(得分:0)

确保您遵循Theano Install

的安装程序

对于我来说,在Windows环境中&amp; Python 3.6以下的技巧

>>> conda install numpy scipy mkl-service libpython m2w64-toolchain nose sphinx pydot-ng git

>>> conda install theano pygpu