git clone https://github.com/tensorflow/tensorflow cd tensorflow git checkout r1.1
切换1.1版本的代码
进入源码目录,先执行配置文件
$ ./configure Please specify the location of python. [Default is /usr/bin/python]: 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] y jemalloc enabled Do you wish to build TensorFlow with Google Cloud Platform support? [y/N] n No Google Cloud Platform support will be enabled for TensorFlow Do you wish to build TensorFlow with Hadoop File System support? [y/N] 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] 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] n No CUDA support will be enabled for TensorFlow Configuration finished …….. INFO: Starting clean (this may take a while). Consider using –expunge_async if the clean takes more than several minutes. …….. INFO: All external dependencies fetched successfully.
配置完之后执行如下命令编译安装
bazel build –config=opt //tensorflow/tools/pip_package:build_pip_package bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg sudo pip install /tmp/tensorflow_pkg/tensorflow-1.1.0rc0-cp27-none-linux_x86_64.whl
不要在源码目录,随便找一个其他目录,执行python
$python
输入如下代码:
import tensorflow as tf hello = tf.constant(‘Hello, TensorFlow!’) sess = tf.Session() print(sess.run(hello))
终端打印如下语句:
Hello, TensorFlow!
perfect, 搭建完毕,现在可以开始编程了,万里长征迈出了第一步,加油!