Ubuntu:从源码安装tensorflow r1.0 - Install TensorFlow r1.0 from Sources

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/oukohou/article/details/64440501

官方链接:install tensorflow from sources

本文记录如何从源码安装tensorflow1.0,CPU版本,Python 2.7:

1. 安装依赖:bazel,Tensorflow Python dependencies

1)Bazel:

官方链接:install bazel on Ubuntu
1.install JDK 8 :

$ sudo add-apt-repository ppa:webupd8team/java
$ sudo apt-get update
$ sudo apt-get install oracle-java8-installer

我电脑已经有了jdk,所以跳过这一步,验证:
jdk验证

2.install bazel:

$ 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 -
$ sudo apt-get update && sudo apt-get install bazel
$ sudo apt-get upgrade bazel

2)Tensorflow Python dependencies:

包括:numpy,dev,pip,wheel

$ sudo apt-get install python-numpy python-dev python-pip python-wheel

2. 安装tensorflow:

1)Clone the TensorFlow repository:

这里用到git,如需安装,参见install git

$ git clone https://github.com/tensorflow/tensorflow
$ cd tensorflow
$ git checkout r1.0

2.Configure the installation

还是在刚刚的文件夹目录下,命令行输入:

$ 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
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 JIT support will be enabled for TensorFlow
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/local/lib/python2.7/dist-packages]
Using python library path: /usr/local/lib/python2.7/dist-packages
Do you wish to build TensorFlow with OpenCL support? [y/N] N
No OpenCL support will be enabled for TensorFlow
Do you wish to build TensorFlow with CUDA support? [y/N] Y
CUDA support will be enabled for TensorFlow
Please specify which gcc should be used by nvcc as the host compiler. [Default is /usr/bin/gcc]:
Please specify the Cuda SDK version you want to use, e.g. 7.0. [Leave empty to use system default]: 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 the cuDNN version you want to use. [Leave empty to use system default]: 5
Please specify the location where cuDNN 5 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
Setting up Cuda include
Setting up Cuda lib
Setting up Cuda bin
Setting up Cuda nvvm
Setting up CUPTI include
Setting up CUPTI lib64
Configuration finished

根据自己需要选择就好了。

3)Build the pip package

命令号运行:

$ bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package

这一步会比较耗内存,如果对电脑没信心的话,可以加上“–local_resources 2048,.5,1.0 while invoking bazel”:

$ bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package --local_resources 2048,.5,1.0 while invoking bazel

之后会是漫长的等待,我的电脑足足跑了1个小时,不过我们离成功已经很近了,加油!再输入:

$ bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg

这一步会生成 .whl文件,聪明的你肯定知道这就是黎明前的曙光了,没错,接下来,我们:

4)Install the pip package

你的 .whi 文件会在“/tmp/tensorflow_pkg”目录下,没错,找到它,然后输入:

$ sudo pip install /tmp/tensorflow_pkg/name-of-you-whl.whl

比如我的文件名是-“tensorflow-1.0.1-cp27-cp27mu-linux_x86_64.whl”,所以就输入:

$ sudo pip install /tmp/tensorflow_pkg/ tensorflow-1.0.1-cp27-cp27mu-linux_x86_64.whl

OK,now check it out.

3.Validate your installation

点个赞再走呗大爷

以上,幸会。
个人github链接:oukohou的git ,后续会迁移一些东西,暂时比较空。
个人微信公共号:oukohou
oukohou的公众号
hello there.
Scan and we will see.

猜你喜欢

转载自blog.csdn.net/oukohou/article/details/64440501