Tensorflow安装教程

1.首先进行虚拟环境建立:

cmd命令下输入activate激活base环境,输入下面代码,创建虚拟环境:

conda create –n tensorflow python=3.7

2.接着从下面网站查找所对应的tensorflow版本,这里面并不一定包含所有版本信息:

在 Windows 环境中从源代码构建  |  TensorFlow (google.cn)https://tensorflow.google.cn/install/source_windows#tensorflow_2x3.在然后从一下网站找到对应版本安装命令:

tensorflow-gpu · PyPIhttps://pypi.org/project/tensorflow-gpu/#history4.在然后进行换源安装:

国内镜像地址:

阿里云 
http://mirrors.aliyun.com/pypi/simple/

中国科技大学 
https://pypi.mirrors.ustc.edu.cn/simple/

豆瓣(douban) 
http://pypi.douban.com/simple/

清华大学 
https://pypi.tuna.tsinghua.edu.cn/simple/

中国科学技术大学 
http://pypi.mirrors.ustc.edu.cn/simple/

下面是用豆瓣安装示例:

pip install tensorflow-gpu==1.13.2 -i https://pypi.douban.com/simple --trusted-host pypi.douban.com

有些版本该镜像网站没有,可以尝试换个镜像网站。

5.如果安装错误,卸载命令为:

pip uninstall tensorflow-gpu

6.检查报错信息,循环尝试别的版本,实在不行装CPU版本,直到安装成功。

7.我的环境CUDA为10.0cudnn版本为7.4.15,python为3.7,tensorflow为1.13.2,用上面方法安装,测试是否成功时报错:

TypeError: Descriptors cannot not be created directly.
If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0.
If you cannot immediately regenerate your protos, some other possible workarounds are:
 1. Downgrade the protobuf package to 3.20.x or lower.
 2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower).

于是我去安装低版本的protobuf,安装命令为:

pip install protobuf==3.20.1

安装前可以用conda list查看自己当前版本信息,测试代码为:

激活虚拟环境后输入python,复制下面代码:

import tensorflow as tf 
sess = tf.Session() 
a = tf.constant(2) 
b = tf.constant(2) 
print(sess.run(a+b)) 

输出结果为4,测试成。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值