Ubuntu16.04版本安装Anaconda+Tensorflow
Ubuntu16.04系统下安装软件一直是“心头大患”,特别是安装Anacondahe和Tensorflow,可以说是一波三折。为了不让大家走弯路,快速的完成Anacondahe和Tensorflow的安装使用,本文结合自身的亲身体验介绍一个进行成功案列,既简单又实用。安装前确保Ubuntu16.04已经安装好,方法步骤:
1.安装Anaconda
首先到Anaconda官网点击打开链接下载安装文件,由于是Ubuntu16.04系统,这里下载Anaconda3-4.2.0-Linux-x86_64.sh版本(Python for 3.5)。
下载完成后将.sh文件放到目录下(本人放到/home/guoguo16/下载目录下)。
然后打开终端(Terminal),输入命令cd/home/guoguo16/下载(根据个人放的目录进行改变)
最后在文件路径下执行命令:bash Anaconda3-4.2.0-Linux-x86_64.sh
即可完成安装Anaconda,可通过输入命令python进行验证。
2.安装Tensorflow
由于已安装完成了Anaconda(以Python=3.5为例),本文将在Anaconda环境下通过下面步骤进行安装:
(1)首先创建名为tensorflow的conda环境,在终端输入命令:
$ conda create -n tensorflow
(2)激活conda,进入tensorflow环境
$ source activate tensorflow(tensorflow)$ # Your prompt should change
附:退出tensorflow环境可执行
$ source deactivate tensorflow
(3)安装tensorflow,在这里介绍两种方法(都需要连网)
①直接下载tensorflow安装文件点击打开链接,然后cd到tensorflow存放目录下,执行命令:
(tensorflow)$pip install --ignore-installed --upgrade /home/guoguo16/下载/tensorflow_gpu-1.3.0-cp35-cp35m-linux_x86_64.whl
即可安装完成。
②直接安装,执行命令:
(tensorflow)$ pip install --ignore-installed --upgrade \https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.3.0-cp35-cp35m-linux_x86_64.whl
执行以下代码:
#Python
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))
若输出:
Hello, TensorFlow!
则安装成功!
提示:在执行sess = tf.Session()时,会出现:
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE3 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
Those are warnings, not errors (as indicated by theW after the colon. Errors have an E there)到这里大家已经成功安装Anaconda+Tensorflow,可以尽情享受Tensorflow带来的乐趣了,我的Weibo将于大家一起分享最前沿的人工智能、机器学习、深度学习与计算机视觉方面的技术。