Ubuntu18.04下基于Anaconda安装TensorFlow1.8-GPU


前置条件:


1. 创建TensorFlow环境

通过以下命令建立一个叫做 tensorflow 的 conda 环境来运行某一版本的 Python.

conda create -n tensorflow pip python=3.6
#conda create -n tensorflow pip python=2.7   如果是2.7版本就选择这条命令

安装完成如图所示:
在这里插入图片描述

2. 激活环境

使用如下命令来激活 conda 环境:

source activate tensorflow
#(tensorflow)$  # 这时你的前缀应该变成这样 

3. 安装TensorFlow-GPU

由于通过下载的方式安装较慢,所以本人直接先将安装包下载好,拷贝至目录下。
官网下载地址:https://www.tensorflow.org/versions/?hl=zh-cn
(可以在官网中选择自己需要的版本进行下载)
运行如下格式的命令来在你的 conda 环境中安装 TensorFlow:

pip install tensorflow_gpu-1.8.0-cp36-cp36m-manylinux1_x86_64.whl

4. 验证

终端输入python

import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))

到此输出Hello,TensorFlow!无错误,表示安装成功~


如果出现警告:

I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA

可以忽略或通过以下方法解决:
在代码前面添加以下两行代码即可.

import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
  • 2
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值