Python 导入 theano 给出了 AttributeError: module 'theano' has no attribute 'gof'

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41174995/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 00:30:58  来源:igfitidea点击:

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

pythontheanokeras

提问by uncommon_name

I have python 3. I installed "Theano" bleeding edge and "Keras" using

我有 python 3。我安装了“Theano”前沿和“Keras”使用

pip install --upgrade --no-deps git+git://github.com/Theano/Theano.git

and also

并且

pip install --upgrade git+git://github.com/Theano/Theano.git

and

pip install git+git://github.com/fchollet/keras.git

But when I try to import Theano, I receive the following error:

但是当我尝试导入 Theano 时,我收到以下错误:

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

I looked for a solution online and reached nothing...

我在网上寻找解决方案,但一无所获...

This is the piece of code I receive an error on (the last line produces error):

这是我收到错误的一段代码(最后一行产生错误):

import sys
import numpy as np
import pandas as pd
from sklearn import preprocessing

from keras.models import Sequential

Since I don't have enough experience with python I'm completely lost and can't figure out what to do...

由于我对 python 没有足够的经验,我完全迷失了,不知道该怎么做......

Any help would be appreciated.

任何帮助,将不胜感激。

回答by glS

The problem arises from a broken installation of theano and has nothing to do with keras itself.

问题出自 theano 安装损坏,与 keras 本身无关。

This error seems to be due to conflicts in the installed version of theano, as also suggested in this answerto a related question.

这个错误似乎是由于安装的 theano 版本中的冲突造成的,正如在这个对相关问题的回答中所建议的那样。

An easy way that should solve the problem without having to fiddle with the installed version and all that is to use condaas package manager and let it do the dirty work. If you choose to do this be aware that you should manage all of your python modules with it (even though with the latest versions you can install packages with the pipshipped with anaconda itself).

一种简单的方法可以解决问题,而不必摆弄已安装的版本以及conda用作包管理器并让它做肮脏工作的所有内容。如果您选择这样做,请注意您应该使用它管理所有的 python 模块(即使使用最新版本,您可以安装pip带有 anaconda 本身的软件包)。

See the official documentationfor how to install Anaconda. Once anaconda is set up you can install theano using simply conda install theano.

有关如何安装 Anaconda,请参阅官方文档。设置 anaconda 后,您可以使用简单的conda install theano.

With condais also often convenient to install the packages needed for some particular application, like Keras in your case, in an environment isolated from the rest of your python installation, for easier maintenance. Read the relevant docsto see how this would work.

在与condaPython 安装的其余部分隔离的环境中,安装某些特定应用程序所需的包通常也很方便,例如您的 Keras,以便于维护。阅读相关文档以了解这是如何工作的。

回答by Turanga1

I used conda to install theano and still got the same error. After much trial and error and StackOverflow searches, what worked for me was to first run:

我使用 conda 来安装 theano,但仍然出现相同的错误。经过多次反复试验和 StackOverflow 搜索,对我有用的是首先运行:

conda install m2w64-toolchain

followed by:

其次是:

conda install theano

Alternatively you can chain the modules together when you create an environment, for example:

或者,您可以在创建环境时将模块链接在一起,例如:

conda create -n myenv python=3.5 m2w64-toolchain theano

Also important to follow @gtnbz2nyt's advice and restart your Python instance.

遵循@gtnbz2nyt 的建议并重新启动 Python 实例也很重要。

回答by cei_

The problem seems to be with your g++ compiler. Try uninstalling it and running your script again. It'll spit a warning implying a degradation in performance, but it'll work nonetheless.

问题似乎出在您的 g++ 编译器上。尝试卸载它并再次运行您的脚本。它会发出暗示性能下降的警告,但它仍然会起作用。

'Python 3.6.3 |Anaconda custom (32-bit)| 
(default, Oct 15 2017, 07:29:16)       
[MSC v.1900 32 bit (Intel)]
Type "copyright", "credits" or "license" for more information.

IPython 6.1.0 -- An enhanced Interactive Python.

import theano
WARNING (theano.tensor.blas): Using NumPy C-API based implementation 
for BLAS functions.
'