Python3.7安装Tensorflow(CPU、Windows版)
环境:下载安装的 Anaconda3-5.3.1-Windows-x86_64,对应的 Python3.7 版本
系统:Windows10
安装步骤:
1. cmd窗口下:
pip install tensorflow
报错:
-
ERROR: tensorboard 1.14.0 has requirement setuptools>=41.0.0, but you’ll have setputools 40.2.0 which is incompatible.
分析:setuptools 版本低
解决方式:升级 setuptools,命令如下
pip install --upgrade setuptools
-
ERROR: Connot uninstall ‘wrapt’. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
分析:无法卸载 wrap
解决方式:输入如下命令
pip install -U --ignore-installed wrapt enum34 simplejson netaddr
解决以上报错后,重新安装 TensorFlow:
pip install tensotflow
2. 安装成功后,运行矩阵相乘示例
import tensorflow as tf
# 新建 graph(x 和 y 矩阵相乘)
x = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='x')
y = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='y')
res = tf.matmul(x, y)
sess = tf.Session() # 新建 Session
print (sess.run(res)) # 执行任务
sess.close() # 任务完成,关闭会话
报错:
-
ImportError: numpy.core.multiarray failed to import
分析:numpy 版本不匹配
解决方式:卸载 numpy 模块,重新安装 numpy 1.16 版本,命令如下
pip install uninstall numpy
pip install numpy==1.16
注意:若采用直接升级 numpy 的方式,会产生告警
pip install --upgrade numpy
分析:numpy 版本过高,仍需要卸载重装 numpy 的 1.16 版本。
重新执行矩阵相乘示例:
import tensorflow as tf
# 新建 graph(x 和 y 矩阵相乘)
x = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='x')
y = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='y')
res = tf.matmul(x, y)
sess = tf.Session() # 新建 Session
print (sess.run(res)) # 执行任务
sess.close() # 任务完成,关闭会话
[[22. 28.]
[49. 64.]]
3. 查看TensorFlow的CPU或GPU信息
from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())
[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 16849555306325178480
]
分析:可通过此方式查看安装的 TensorFlow 为 CPU 版本
搞定,欢迎关注我的博客,谢谢大家,撒花 o(* ̄︶ ̄*)o