anaconda安装tensorflow遇到的一个错误
笔者在conda环境 python=3.8安装tensorflow-2.5.0,因为这个2.5.0版本与笔者的CUDA版本是匹配的,结果安装好后,在python环境里执行“import tensorflow as tf”就报了一大堆错误:
(keras) C:\Users\daniel>python
Python 3.8.5 (default, Sep 3 2020, 21:29:08) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
Traceback (most recent call last):File "C:\Users\daniel\anaconda3\envs\keras\lib\site-packages\numpy\__init__.py", line 320, in __getattr__raise AttributeError("module {!r} has no attribute "
AttributeError: module 'numpy' has no attribute 'typeDict'
C:\Users\daniel\anaconda3\envs\keras\lib\site-packages\tensorflow\python\framework\dtypes.py:511: FutureWarning: In the future `np.object` will be defined as the corresponding NumPy scalar.np.object,
Traceback (most recent call last):File "<stdin>", line 1, in <module>File "C:\Users\daniel\anaconda3\envs\keras\lib\site-packages\tensorflow\__init__.py", line 41, in <module>from tensorflow.python.tools import module_util as _module_utilFile "C:\Users\daniel\anaconda3\envs\keras\lib\site-packages\tensorflow\python\__init__.py", line 46, in <module>from tensorflow.python import dataFile "C:\Users\daniel\anaconda3\envs\keras\lib\site-packages\tensorflow\python\data\__init__.py", line 25, in <module>from tensorflow.python.data import experimentalFile "C:\Users\daniel\anaconda3\envs\keras\lib\site-packages\tensorflow\python\data\experimental\__init__.py", line 99, in <module>from tensorflow.python.data.experimental import serviceFile "C:\Users\daniel\anaconda3\envs\keras\lib\site-packages\tensorflow\python\data\experimental\service\__init__.py", line 140, in <module>from tensorflow.python.data.experimental.ops.data_service_ops import distributeFile "C:\Users\daniel\anaconda3\envs\keras\lib\site-packages\tensorflow\python\data\experimental\ops\data_service_ops.py", line 25, in <module>from tensorflow.python.data.experimental.ops import compression_opsFile "C:\Users\daniel\anaconda3\envs\keras\lib\site-packages\tensorflow\python\data\experimental\ops\compression_ops.py", line 20, in <module>from tensorflow.python.data.util import structureFile "C:\Users\daniel\anaconda3\envs\keras\lib\site-packages\tensorflow\python\data\util\structure.py", line 26, in <module>from tensorflow.python.data.util import nestFile "C:\Users\daniel\anaconda3\envs\keras\lib\site-packages\tensorflow\python\data\util\nest.py", line 40, in <module>from tensorflow.python.framework import sparse_tensor as _sparse_tensorFile "C:\Users\daniel\anaconda3\envs\keras\lib\site-packages\tensorflow\python\framework\sparse_tensor.py", line 28, in <module>from tensorflow.python.framework import constant_opFile "C:\Users\daniel\anaconda3\envs\keras\lib\site-packages\tensorflow\python\framework\constant_op.py", line 29, in <module>from tensorflow.python.eager import executeFile "C:\Users\daniel\anaconda3\envs\keras\lib\site-packages\tensorflow\python\eager\execute.py", line 27, in <module>from tensorflow.python.framework import dtypesFile "C:\Users\daniel\anaconda3\envs\keras\lib\site-packages\tensorflow\python\framework\dtypes.py", line 511, in <module>np.object,File "C:\Users\daniel\anaconda3\envs\keras\lib\site-packages\numpy\__init__.py", line 305, in __getattr__raise AttributeError(__former_attrs__[attr])
AttributeError: module 'numpy' has no attribute 'object'.
`np.object` was a deprecated alias for the builtin `object`. To avoid this error in existing code, use `object` by itself. Doing this will not modify any behavior and is safe.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
从错误的提示看来是numpy版本不匹配,这里的numpy版本是1.24.3,有点高了。于是降级也不成,因为numpy被一大堆安装包所依赖,删除numpy会删除几乎整个tensorflow环境。在网上搜索了一番,于是尝试降低python版本为3.6,再安装tensorflow-2.5.0,结果import tensorflow时,直接报python版本不匹配,于是在python版本3.7下再安装tensorflow-2.5.0,导入tensorflow时,没有报错,整个过程简直就是恶作剧一场!半天时间就这么没了。
Python 3.7.16 (default, Jan 17 2023, 16:06:28) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> tf.__version__
'2.5.0'
>>> import numpy as np
>>> np.__version__
'1.21.5'