Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: type object 'numpy.ndarray' has no attribute '__array_function__'

I upgraded numpy to the latest version and now I am getting following error on importing numpy:

AttributeError: type object 'numpy.ndarray' has no attribute 'array_function'

I am using numpy version 1.16.

like image 819
Muhammad Hassan Avatar asked Jan 14 '19 06:01

Muhammad Hassan


2 Answers

Uninstall all installs of Numpy using

pip uninstall numpy

for python3

pip3 uninstall numpy

You may need to run the uninstall command several times since several versions of numpy may be installed. Then run

pip install numpy
like image 95
Ajinkya Prabhu Avatar answered Nov 08 '22 05:11

Ajinkya Prabhu


This seems to be an ongoing issue (with the recent release of Numpy 1.16.0 there was a rash of related bug reports). There's a whole bunch more info about the causes of and fixes for this bug on an issue thread on Numpy's Github.

The problem

As described in the issue, the problem is caused by path conflicts between the files of different Numpy versions. They also suggest that there may be an issue with older versions of pip (specifically, there used to be an issue with how pip uninstalled (or failed to uninstall) old versions of Numpy).

The fix

The Numpy dev recommend fix is to first upgrade your pip:

pip install -U pip

then uninstall/reinstall the latest version of Numpy (this does both in a single command):

pip install -U numpy

If that doesn't work

Some people ended up having stranger path conflicts that they were unable to resolve just by reinstalling with pip. If the above steps fail, check to see if you have any old installs of Numpy anywhere on your filesystem. If you do, get rid of them and then try reinstalling Numpy again.

like image 5
tel Avatar answered Nov 08 '22 04:11

tel