tensorflow1.5源码安装
昨天听同学说
TensorFlow1.5.0-rc0 发布了,该版本将动态图集成到了tensorflow模块里面,不用像1.4的版本需要另外安装插件,很是激动,打算赶紧安装上手一波。但是由于才发布不久,不支持终端的pip直接安装,所以要想使用最新版本,还得自己编译源码安装。
话不多说,直接动手!(tensorflow CPU版本安装,渣渣笔记本
)

环境:
ubuntu14.04、python2.7
tensorflow安装环境准备
1、Bazel安装
Bazel是一个构建工具,即一个可以运行编译和测试来组装软件的工具,跟Make、Ant、Gradle、Buck、Pants和Maven一样。Bazel官网安装教程。选择官网推荐的第一种安装方式
Use our custom APT repository (recommended)。
第一步 install JDK 8。
ubuntu14.04应该先添加PPA,终端输入命令:
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update && sudo apt-get install oracle-java8-installer
第二
句我执行时报了错,但是分开执行就通过了,即先执行
sudo apt-get update
然后执行
sudo apt-get install oracle-java8-installer
sudo apt-get install oracle-java8-installer。
第二步
Add Bazel distribution URI as a package source (one time setup),执行命令:
echo"deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8"| sudo tee /etc/apt/sources.list.d/bazel.list
curl https://bazel.build/bazel-release.pub.gpg | sudo apt-key add -
第二句我执行的时候报了错,提示没有***gpg,第二天写的这个记录,具体的错忘了
。于是先把密钥下载下来吧,直接在浏览器地址栏输入https://bazel.build/bazel-release.pub.gpg,然后就可以下载该密钥文件了,然后将密钥文件拷贝到某路径path下,再执行命令

sudo apt-key add path/密钥文件名
第三步 安装Bazel,执行命令
sudo apt-get update&& sudo apt-get install bazel
实际上执行完这几步就可以了,在终端输入baz ,双击Tab键可以看到提示的命令中会出现bazel命令。
2、python依赖包安装
输入命令
sudo apt-get install python-numpy python-dev python-pip python-wheel (适用于python2.7)
3、源码信息确认
首先解压上面步骤中下载的源码包,解压包并进入到根目录
tar -zxvf tensorflow包名
cd tensorflow解压目录
./configure
出现如下配置信息:
$ cd tensorflow # cd to the top-level directory created
$ ./configure
Please specify the location of python. [Default is /usr/bin/python]: /usr/bin/python2.7
Found possible Python library paths:
/usr/local/lib/python2.7/dist-packages
/usr/lib/python2.7/dist-packages
Please input the desired Python library path to use. Default is [/usr/lib/python2.7/dist-packages]
Using python library path: /usr/local/lib/python2.7/dist-packages
Do you wish to build TensorFlow with MKL support? [y/N]
No MKL support will be enabled for TensorFlow
Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -march=native]:
Do you wish to use jemalloc as the malloc implementation? [Y/n]
jemalloc enabled
Do you wish to build TensorFlow with Google Cloud Platform support? [y/N]
No Google Cloud Platform support will be enabled for TensorFlow
Do you wish to build TensorFlow with Hadoop File System support? [y/N]
No Hadoop File System support will be enabled for TensorFlow
Do you wish to build TensorFlow with the XLA just-in-time compiler (experimental)? [y/N]
No XLA support will be enabled for TensorFlow
Do you wish to build TensorFlow with VERBS support? [y/N]
No VERBS support will be enabled for TensorFlow
Do you wish to build TensorFlow with OpenCL support? [y/N]
No OpenCL support will be enabled for TensorFlow
Do you wish to build TensorFlow with CUDA support? [y/N] N
Please specify the Cuda SDK version you want to use, e.g. 7.0. [Leave empty to default to CUDA 8.0]: 8.0
Please specify the location where CUDA 8.0 toolkit is installed. Refer to README.md for more details. [Default is /usr/local/cuda]:
Please specify which gcc should be used by nvcc as the host compiler. [Default is /usr/bin/gcc]:
Please specify the cuDNN version you want to use. [Leave empty to default to cuDNN 6.0]: 6
Please specify the location where cuDNN 6 library is installed. Refer to README.md for more details. [Default is /usr/local/cuda]:
Please specify a list of comma-separated Cuda compute capabilities you want to build with.
You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
Please note that each additional compute capability significantly increases your build time and binary size.
[Default is: "3.5,5.2"]: 3.0
Do you wish to build TensorFlow with MPI support? [y/N]
MPI support will not be enabled for TensorFlow
Configuration finished
根据自己的需要进行选择,我没有选择cuda选项。
然后编译pip包,输入命令(会编译很长时间)
bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package
在tensorflow的根目录下执行
bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
会在/tmp/tensorflow_pkg/下生成tensorflow-1.5.0rc0-cp27-cp27mu-linux_x86_64.whl
安装tensorflow
执行命令
sudo pip install --ignore-installed --upgrade /tmp/tensorflow_pkg/tensorflow-1.5.0rc0-cp27-cp27mu-linux_x86_64.whl
安装可能会遇到如下错误(参考链接)
tensorflow-1.5.0rc0-cp27-cp27mu-linux_x86_64.whl is not a supported wheel on this platform.
Storing debug log for failure in /home/xxx/.pip/pip.log
这是因为pip版本的缘故,解决办法是下载get-pip.py 文件,进入下载目录执行
$sudo python2.7 get-pip.py
再次安装即可
另启动一个终端,启动python环境,导入tensorflow包看是否成功