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,测试成。