Python3.7安装Tensorflow(CPU、Windows版)

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

  • 4
    点赞
  • 29
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值