8

I'm running this simple example:

import theano
x = theano.tensor.dscalar()
f = theano.function([x], 2*x)
f(4)

and I get:

AttributeError: ('The following error happened while compiling the node', Elemwise{mul,no_inplace}(TensorConstant{2.0}, <TensorType(float64, scalar)>), '\n', "module 'numpy.core.multiarray' has no attribute '_get_ndarray_c_version'")

I though it must be a numpy error, so I try to update but I have the latest version as far as I know:

import numpy

numpy.version.version
'1.16.2'

I'm running all this in spyder but that seems to be irrelevant since I get the same error in python interpreter

Makis Kans
  • 337
  • 3
  • 12
  • you need to downgrade the numpy version to the 1.16.0 (have you upgrade or install any library before having this error for the first time?) – Frayal Mar 07 '19 at 14:51

2 Answers2

10

This is a known bug presumably caused by changes introduced in NumPy. A fix for this was introduced in Theano v1.0.4. So, either you need to upgrade to at least that version of Theano, or downgrade NumPy to below v1.16.

Note that at the moment (25 July 2019) only Conda Forge has Theano v1.0.4, whereas Anaconda has v1.0.3. So you need to run

conda install -c conda-forge theano=1.0.4

Otherwise, the NumPy downgrade is

conda install numpy=1.15
merv
  • 67,214
  • 13
  • 180
  • 245
  • I'm using Anaconda and when I go to update theano, it's still the v.1.0.3. How do I downgrade NumPy? – DataGirl Jul 18 '19 at 17:36
  • 2
    @DataGirl sorry for the delayed response. I've updated the answer with explicit instructions. – merv Jul 26 '19 at 01:27
3

Go to the

Anaconda3\pkgs\theano-1.0.3-py37_0\Lib\site-packages\theano\gof

open cc.py

go to line 1376

comment these code:

sig.append('NPY_ABI_VERSION=0x%X' %
        np.core.multiarray._get_ndarray_c_version())

like this

For more details you can Refer:

https://github.com/MichalDanielDobrzanski/DeepLearningPython35/issues/20

https://www.wandouip.com/t5i268914/

Narendra Chouhan
  • 2,291
  • 1
  • 15
  • 24
  • 1
    Well, if you're going to go as far as editing the source (not recommended since it violates the reproduciblity of the env), I'd at least encourage you to change it to match [the actual patch that was done](https://github.com/Theano/Theano/commit/5953f2d6e4a305852fa6e3f3ae28da2a40cdaf41). – merv Jul 26 '19 at 01:07