Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

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:

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...

Any help would be appreciated.

like image 424
uncommon_name Avatar asked Dec 15 '16 23:12

uncommon_name


2 Answers

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

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

An easy way that should solve the problem without having to fiddle with the installed version and all that is to use conda as 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 pip shipped with anaconda itself).

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

With conda is 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 docs to see how this would work.

like image 134
glS Avatar answered Sep 17 '22 11:09

glS


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 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.

like image 45
Turanga1 Avatar answered Sep 19 '22 11:09

Turanga1