记一下,以后配系统自己方便
这篇文章主要参考了大佬的博客
https://blog.csdn.net/qq_30520759/article/details/78947034
首先安装cuda+cudnn就不说了,看我前面的博客
https://blog.csdn.net/qq_36852276/article/details/89207599
我装的是cuda9.0+cudnn7.0
然后就开始安装tensorflow,这里有一个很关键的地方是gcc编译器要降级到5.0以下,因为默认的gcc编译器是5.4的 查看gcc版本可以用
gcc -v
然后降级的方法是
sudo apt-get install g++-4.9
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 20
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 10
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.9 20
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 10
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30
sudo update-alternatives --set cc /usr/bin/gcc
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30
sudo update-alternatives --set c++ /usr/bin/g++
一条一条在终端里输入就行,然后查看gcc版本对不对
然后就可以安装了,我采用的是最简单的pip3安装,因为我用的是python3
sudo pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple tensorflow-gpu==1.12
这里我直接换了个清华源,安装速度快了很多
这里注意以下我之前没有设置强制安装1.12版本的,然后import的时候会报错,自动会安装最新版本的是1.13,可能和我安装的cuda版本不对应?反正安装低版本的就没事,如果出现了同样的错误不妨安装低版本的试一试
然后就安装好了
测试一下
在终端输入
python3
然后在python3环境下
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))
如果会出现hello 就说明安装好了
然后安装以tensorflow为后端的keras
sudo pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple keras
然后再安装jupyter,我装的时候没遇到什么问题,直接用pip3去装就ok了,而且在里面测试tensorflow也没什么问题
sudo pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple jupyter
记一下tensorflow降级的办法,这里是降到1.9
sudo pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple -U --pre tensorflow-gpu==1.9
pytorch安装
经过其他人不断安利,我准备入坑pytorch
pytorch可以说是我见过最好安装的东西了(前提是安装好cuda+cudnn),先打开官网pytorch官网,找到自己对应版本的 os+cuda+cudnn
然后按照命令,一行命令就安装了
我的是cuda9.0,就按他给的在终端输入
pip3 install torch torchvision
等待,就装好了
验证是否安装成功,在python3环境下
import torch
不报错就ok
验证GPU是否可用
print(torch.cuda.is_available())
返回True就表明可以使用GPU