报错内容
在import tensorflow时报错,报错内容如下:
(xx) C:\Users\cxz_w>python
Python 3.6.9 |Anaconda, Inc.| (default, Jul 30 2019, 14:00:49) [MSC v.1915 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
D:\Anacoda\Anaconda\envs\xx\lib\site-packages\tensorflow\python\framework\dtypes.py:523: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint8 = np.dtype([("qint8", np.int8, 1)])
D:\Anacoda\Anaconda\envs\xx\lib\site-packages\tensorflow\python\framework\dtypes.py:524: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_quint8 = np.dtype([("quint8", np.uint8, 1)])
D:\Anacoda\Anaconda\envs\xx\lib\site-packages\tensorflow\python\framework\dtypes.py:525: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint16 = np.dtype([("qint16", np.int16, 1)])
D:\Anacoda\Anaconda\envs\xx\lib\site-packages\tensorflow\python\framework\dtypes.py:526: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_quint16 = np.dtype([("quint16", np.uint16, 1)])
D:\Anacoda\Anaconda\envs\xx\lib\site-packages\tensorflow\python\framework\dtypes.py:527: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint32 = np.dtype([("qint32", np.int32, 1)])
D:\Anacoda\Anaconda\envs\xx\lib\site-packages\tensorflow\python\framework\dtypes.py:532: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
np_resource = np.dtype([("resource", np.ubyte, 1)])
报错原因
numpy版本过高,本人报错时numpy是比1.17版更高的版本。
解决办法
1.打开终端
运行 -> cmd
2.在终端下输入 activate environment_name
注意:environment_name需要换成自己anaconda里具体的环境名,即需要替换下列代码中的xx。
C:\Users\cxz_w>activate xx
3.进入到环境后,输入下列代码(注意查看PS里的内容)
(xx) C:\Users\cxz_w>pip install numpy==1.16.0
PS:以上便算完成所有操作,第三步更新可能会特别慢,可以更改下载源来提速,将第三步的代码更改为如下形式
pip install --upgrade numpy -i https://pypi.tuna.tsinghua.edu.cn/simple
结果
(xx) C:\Users\cxz_w>python
Python 3.6.9 |Anaconda, Inc.| (default, Jul 30 2019, 14:00:49) [MSC v.1915 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
>>> tensorflow.__version__
'1.9.0'
>>>
后记
问题完美解决,可以愉快地使用了!
因为在CSDN上得到过太多帮助,也希望自己能对其他人有所帮助。