tensorflow1.8 GPU版本安装 (python3.6+win10+1060+cuda9.2+vs2017+keras)

tensorflow安装

1.先安装anaconda 3.6版本

https://www.anaconda.com/download/
测试:
cmd里面输入python,有信息就行了。

2.安装VS2017

https://visualstudio.microsoft.com/zh-hans/downloads/

选择学生版的就可以。
安装选择C++的模块就可以(我选的前3个基础的),因为tensorflow需要C++编译器。

3.安装cuda9.2

这个最难弄。
首先一般安装时,

3.1先确定安装的tensorflow版本需要的最低版本。

tensorflow1.8需要cuda9.0。这个去官网看。
https://tensorflow.google.cn/install/

3.2然后看看你的显卡对应的驱动需要什么版本的cuda。

方法参考:https://blog.csdn.net/qq_33856151/article/details/79295086
我的信息:
《tensorflow1.8 GPU版本安装 (python3.6+win10+1060+cuda9.2+vs2017+keras)》
有时候也不太准,可以在附近的几个版本试一下。版本不对时,安装会出现下图:
《tensorflow1.8 GPU版本安装 (python3.6+win10+1060+cuda9.2+vs2017+keras)》
cuda各版本地址:
https://developer.nvidia.com/cuda-toolkit-archive
我的安装选择:
《tensorflow1.8 GPU版本安装 (python3.6+win10+1060+cuda9.2+vs2017+keras)》

3.3下载对应cuda版本的补丁包cudnn:

cudnn网址:https://developer.nvidia.com/cudnn
这个需要注册一个账号。
选择对应的版本下载,解压cudnn-9.2-windows10-x64-v7.1.zip,将文件夹里的内容拷贝到CUDA的安装目录并覆蓋相应的文件夹(cudnn里的文件分别放到cuda目录里对应位置就行)。
CUDA默认安装目录:C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.2
cudnn目录:
《tensorflow1.8 GPU版本安装 (python3.6+win10+1060+cuda9.2+vs2017+keras)》

4.创建环境+安装tensorflow

cmd里面输入:
conda create -n tensorflow-gpu python=3.6(创建环境)
activate tensorflow-gpu(激活环境)
conda info –envs(验证是否成功)
然后
(不用GPU的)pip install tensorflow
(用GPU的)pip install tensorflow-gpu 但是 由于现在tensorflow对应cuda9.2版本的还没有出来。只能找到某大神github上的编译后的版本,亲测有效。
https://github.com/fo40225/tensorflow-windows-wheel
《tensorflow1.8 GPU版本安装 (python3.6+win10+1060+cuda9.2+vs2017+keras)》

文件放到C:\Users\XXX下面
pip install *.whl

参考:https://blog.csdn.net/wwtor/article/details/80603296

5.检验安装tensorflow:

在cmd输入:
python
import tensorflow
《tensorflow1.8 GPU版本安装 (python3.6+win10+1060+cuda9.2+vs2017+keras)》
没报错可以。
否则错误:
会报错,找不到相关模块,找不到cuda**.dll
应该是cuda的问题。有可能环境变量,或者版本错误吧。

tensorflow装好了,keras就可以安装。 conda install keras。很快。
毕竟只是集成API的工具。

6.安装其他模块后出现的错误

笔者安装matplotlib后,出现 RuntimeError: module compiled against API version 0xc but this version of numpy is 0xb 报错
这个是numpy版本问题。由于大神自带的编译的numpy 1.14.5版本和matplotlib自己安装了numpy 1.13.1的版本冲突。

我解决办法就是每次安装numpy依赖的库时,最后重新安装一遍numpy14的
conda install numpy==1.14.5

点赞