Not able to import numpy: AttributeError: type object 'numpy.ndarray' has no attribute '__array_function__'

Viewed 2454

I am trying to import numpy but I am getting following error:

AttributeError                            Traceback (most recent call last)
<ipython-input-3-38d4b0363d82> in <module>()
----> 1 import pandas

/home/oto/.local/lib/python3.6/site-packages/pandas/__init__.py in <module>()
     11 for dependency in hard_dependencies:
     12     try:
---> 13         __import__(dependency)
     14     except ImportError as e:
     15         missing_dependencies.append(dependency)

/home/oto/.local/lib/python3.6/site-packages/numpy/__init__.py in <module>()
    140     from . import _distributor_init
    141 
--> 142     from . import core
    143     from .core import *
    144     from . import compat

/home/oto/.local/lib/python3.6/site-packages/numpy/core/__init__.py in <module>()
     57 from . import numerictypes as nt
     58 multiarray.set_typeDict(nt.sctypeDict)
---> 59 from . import numeric
     60 from .numeric import *
     61 from . import fromnumeric

/home/oto/.local/lib/python3.6/site-packages/numpy/core/numeric.py in <module>()
   3091 from .umath import *
   3092 from .numerictypes import *
-> 3093 from . import fromnumeric
   3094 from .fromnumeric import *
   3095 from . import arrayprint

/home/oto/.local/lib/python3.6/site-packages/numpy/core/fromnumeric.py in <module>()
     15 from . import numerictypes as nt
     16 from .numeric import asarray, array, asanyarray, concatenate
---> 17 from . import _methods
     18 
     19 _dt_ = nt.sctype2char

/home/oto/.local/lib/python3.6/site-packages/numpy/core/_methods.py in <module>()
    156     )
    157 
--> 158 _NDARRAY_ARRAY_FUNCTION = mu.ndarray.__array_function__
    159 
    160 def _array_function(self, func, types, args, kwargs):

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

How to solve this issue ?

2 Answers

I had the same problem. Just run

rm -rf /home/oto/.local/lib/python3.6/site-packages/numpy*

pip3 install numpy

It worked for me.

remove the whole numpy directory and numpy disc info in the python3.6/site-packages and type pip3 install numpy

I just encounter the same problem today

Related