【问题标题】:Tensorflow AttributeError: type object 'numpy.ndarray' has no attribute '__array_function__'Tensorflow AttributeError:类型对象'numpy.ndarray'没有属性'__array_function__'
【发布时间】:2019-01-15 14:15:55
【问题描述】:

我刚刚 pip 安装了 tensorflow。 现在当我跑 import tensorflow

AttributeError                            Traceback (most recent call last)
<ipython-input-10-8db4a851c0de> in <module>()
----> 1 import tensorflow as tf
      2 from tensorflow import keras
      3 
      4 import numpy as np
      5 import matplotlib.pyplot as plt

~/.local/lib/python3.6/site-packages/tensorflow/__init__.py in <module>()
     22 
     23 # pylint: disable=g-bad-import-order
---> 24 from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
     25 
     26 try:

~/.local/lib/python3.6/site-packages/tensorflow/python/__init__.py in <module>()
     45 # pylint: disable=wildcard-import,g-bad-import-order,g-import-not-at-top
     46 
---> 47 import numpy as np
     48 
     49 from tensorflow.python import pywrap_tensorflow

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

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

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

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

~/.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__'

我已经尝试卸载并重新安装 numpy. 我有numpy-1.16.0

我还看到了一些其他看起来相似的问题。然而这并不是 重复的没有一个解决我的问题。我在导入 tensorflow 时遇到错误。

【问题讨论】:

标签: python python-3.x numpy tensorflow


【解决方案1】:

简单地运行这个,为我解决了:

pip uninstall numpy
pip install numpy

pip uninstall numpy
pip install numpy==1.15.4

【讨论】:

    猜你喜欢
    • 2019-06-08
    • 2019-06-08
    • 1970-01-01
    • 2020-12-03
    • 2020-11-29
    • 2020-10-06
    • 2018-01-25
    • 2016-06-29
    • 2020-03-25
    相关资源
    最近更新 更多