【问题标题】:Cannot import Tensorflow after successfull installation安装成功后无法导入Tensorflow
【发布时间】:2021-11-17 03:46:35
【问题描述】:

Tensorflow 已成功安装在 Conda 环境中,但我无法导入 tensorflow。 我也使用代码更新了 numpy:conda update numpy。我收到以下代码错误:

import tensorflow as tf

Traceback (most recent call last):

  File "<ipython-input-15-64156d691fe5>", line 1, in <module>
    import tensorflow as tf
  File "C:\Users\t\anaconda3\lib\site-packages\tensorflow\__init__.py", line 41, in <module>
    from tensorflow.python.tools import module_util as _module_util
  File "C:\Users\t\anaconda3\lib\site-packages\tensorflow\python\__init__.py", line 45, in <module>
    from tensorflow.python import data
  File "C:\Users\t\anaconda3\lib\site-packages\tensorflow\python\data\__init__.py", line 25, in <module>
    from tensorflow.python.data import experimental
  File "C:\Users\t\anaconda3\lib\site-packages\tensorflow\python\data\experimental\__init__.py", line 96, in <module>
    from tensorflow.python.data.experimental import service
  File "C:\Users\t\anaconda3\lib\site-packages\tensorflow\python\data\experimental\service\__init__.py", line 21, in <module>
    from tensorflow.python.data.experimental.ops.data_service_ops import distribute
  File "C:\Users\t\anaconda3\lib\site-packages\tensorflow\python\data\experimental\ops\data_service_ops.py", line 25, in <module>
    from tensorflow.python.data.experimental.ops import compression_ops
  File "C:\Users\t\anaconda3\lib\site-packages\tensorflow\python\data\experimental\ops\compression_ops.py", line 20, in <module>
    from tensorflow.python.data.util import structure
  File "C:\Users\t\anaconda3\lib\site-packages\tensorflow\python\data\util\structure.py", line 33, in <module>
    from tensorflow.python.ops import tensor_array_ops
  File "C:\Users\t\anaconda3\lib\site-packages\tensorflow\python\ops\tensor_array_ops.py", line 38, in <module>
    from tensorflow.python.ops import array_ops
  File "C:\Users\t\anaconda3\lib\site-packages\tensorflow\python\ops\array_ops.py", line 1475, in <module>
    _NON_AUTOPACKABLE_TYPES = set(np.core.numerictypes.ScalarType)

AttributeError: module 'numpy.core' has no attribute 'numerictypes'

【问题讨论】:

  • 如果您在 Stack Overflow 中搜索“AttributeError: module 'numpy.core' has no attribute 'numerictypes'”,会有一些类似的问题没有答案,但在 cmets 中有一些建议。你试过了吗?
  • 你安装的tensorflow和numpy是什么版本?
  • 是的!请分享 tensorflow 版本和 numpy 版本。也尝试使用以下命令。 pip install numpy -U

标签: python python-3.x numpy tensorflow


【解决方案1】:

为 tensorflow 创建一个新环境并使用以下代码在该环境中重新安装 tensorflow:

conda create -n tf tensorflow python=3.5
conda activate tf

conda install pip
pip install tensorflow

然后再次尝试执行您的代码。如果问题仍然存在,请告诉我们。

【讨论】:

    猜你喜欢
    • 2020-02-11
    • 1970-01-01
    • 1970-01-01
    • 2021-04-11
    • 1970-01-01
    • 2021-06-26
    • 2019-07-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多