首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Theano: AttributeError: module 'theano‘没有属性'gof’

Theano: AttributeError: module 'theano‘没有属性'gof’
EN

Stack Overflow用户
提问于 2017-05-22 08:55:25
回答 3查看 5K关注 0票数 4

这个帖子中提出的解决方案对我不起作用:

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

我已经尝试过conda install theano (适用于jupyter笔记本),尽管安装得很好,我仍然收到上面的错误。

我使用的是Python 3.6,Windows 7,Anaconda/Jupyter notebook,Nvidia 1070 GPU。Theano是.9.0版本

回溯如下:

代码语言:javascript
复制
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重新安装

现在我得到了这个错误:

代码语言:javascript
复制
---------------------------------------------------------------------------
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文件夹的site-packages文件夹中看到了theano。所以不知道问题出在哪里。

问题又回到了:

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

谢谢。

EN

回答 3

Stack Overflow用户

发布于 2017-07-18 15:09:06

对我来说,这是一个笨拙的版本问题。一旦我重新安装我的numpy到版本1.13.1,它就可以工作了。

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

票数 1
EN

Stack Overflow用户

发布于 2017-09-19 22:56:40

对我来说,这是一个编译器问题,它是由于编译时使用了错误的(意外的) g++版本造成的。

除了m2w64-toolchain包(其中包括一个“强烈建议”与theano一起使用的g++编译器,请参阅:installation instructions),我安装了一个cygwin实例,它的g++.exe在windows系统的PATH变量中指向。在import theano期间,使用cygwin版本而不是m2w64-toolchain版本。

另请参阅我找到解决方案的讨论:https://github.com/Theano/Theano/issues/6004

票数 1
EN

Stack Overflow用户

发布于 2018-04-23 11:45:12

确保您遵循Theano Install中的安装过程

对我来说,在windows环境中,Python3.6就做到了

代码语言:javascript
复制
>>> conda install numpy scipy mkl-service libpython m2w64-toolchain nose sphinx pydot-ng git

>>> conda install theano pygpu
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44103230

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档