ubuntu16.04配置tensorflow(GPU)+keras+jupyter notebook +pytorch(GPU)

记一下,以后配系统自己方便
这篇文章主要参考了大佬的博客
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

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值