12

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.

glS
  • 1,209
  • 6
  • 18
  • 45
uncommon_name
  • 470
  • 2
  • 5
  • 19
  • can you make `theano` itself work? do you get an error if you just execute `import theano`? can you run for example the code in some of these examples http://deeplearning.net/software/theano/tutorial/examples.html? Also checkout a [similar question posted on quora](https://www.quora.com/import-theano-command-gives-the-following-error-AttributeError-module-theano-has-no-attribute-gof-Can-someone-explain-why). I've had a very similar problem with running `theano` and solved it by removing it and reinstalling it through `anaconda` – glS Dec 16 '16 at 12:36
  • even import theano gives me an error... I haven't tried partially importing theano, but even if it succeeds, it seems not important since keras is going to import it... I'll try reinstalling it through anaconda. How did you achieve that? – uncommon_name Dec 16 '16 at 18:21
  • 1
    I know nothing about keras but from what you write, especially your having to install theano yourself, it looks like it just uses theano under the hood, so if you cannot make theano itself work you cannot use keras. Googling suggests that that error comes from incompatible numpy version installed, but also your using the development branch means that you should check what versions they are supporting there. Anaconda is a package manager for python, kind of an alternative to `pip`. Once you set it up (see their docs for that) you can install theano simply with `conda install theano` – glS Dec 16 '16 at 18:27
  • also, I guess you already checked this other [similar question](http://stackoverflow.com/a/31530395/4063051)? they use same installation producedure and get the same error – glS Dec 16 '16 at 18:29
  • I can't believe it! using conda to install it worked!!! Thank you, please submit as answer so I can accept – uncommon_name Dec 16 '16 at 19:44

4 Answers4

15

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.

glS
  • 1,209
  • 6
  • 18
  • 45
  • 4
    Just minor addition, be sure to restart your Python instance after you do the conda install otherwise you'll still get the error – gtnbz2nyt Nov 15 '17 at 20:54
  • Does this imply that we need to uninstall everything we did and redo all? – Schütze Dec 22 '17 at 11:19
3

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.

Turanga1
  • 123
  • 1
  • 7
1

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.

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

For macOS Catalina:

conda create -n pymc3 python=3.8
conda activate pymc3
pip install pymc3
vahndi
  • 1,055
  • 8
  • 16