1. 程式人生 > >原始碼安裝 tensorFlow

原始碼安裝 tensorFlow

1,相關下載

            1.1 下載tensorFlow

                                wget https://github.com/tensorflow/tensorflow/archive/v1.0.0-rc0.tar.gz

            1.2 下載bazel

                                在該網頁

                                               

https://github.com/bazelbuild/bazel/releases

                                找到與你的系統對應的bazel-${version}-installer-${os}.sh

                                note:儘量下最新的。

                                PS:我下的是bazel-0.4.5-installer-linux-x86_64.sh

2,安裝依賴包

            2.1 python的依賴包

                                這個就不列舉了,我這邊的環境曾經弄個caffe,所以也不知道具體需要哪些,總之yum install python-pip python-dev python-virtualenv,之後提示缺什麼就用pip安裝什麼就好。

            2.2 bazel

                                一般直接

                                        ./bazel-0.4.5-installer-linux-x86_64.sh --user

                                就可以了,不過我想安裝在自己的目錄下方便管理,所以使用了下面的命令:

                                        mkdir-p /home/spark/xs/tf/bazel/bin

                                        ./bazel-0.4.5-installer-linux-x86_64.sh--prefix=/home/spark/xs/tf/bazel --bin=/home/spark/xs/tf/bazel/bin --base=/home/spark/xs/tf/bazel/.bazel--bazelrc=/home/spark/xs/tf/bazel/.bazelrc

                                然後把/home/spark/xs/tf/bazel/bin新增到環境變數PATH裡

3,安裝tensorFlow

                進入tensorFlow目錄

            3.1配置

                                $ ./configure

                                下面是我的選項,因為我不用GPU,所以最後兩個選的n,如果你用的話要選y

                                Please specifythe location of python. [Default is /usr/bin/python]:直接回車

                                Please specifyoptimization flags to use during compilation when bazel option"--config=opt" is specified [Default is -march=native]:直接回車

                                Do you wish touse jemalloc as the malloc implementation? [Y/n]直接回車

                                jemallocenabled

                                Do you wish tobuild TensorFlow with Google Cloud Platform support? [y/N]n (不需要google雲支援)

                                No GoogleCloud Platform support will be enabled for TensorFlow

                                Do you wish tobuild TensorFlow with Hadoop File System support? [y/N]直接回車

                                No Hadoop FileSystem support will be enabled for TensorFlow

                                Do you wish to build TensorFlowwith the XLA just-in-time compiler (experimental)? [y/N]直接回車

                                No XLA supportwill be enabled for TensorFlow

                                Found possiblePython library paths:

                                  /usr/lib/python2.7/site-packages

                                  /usr/lib64/python2.7/site-packages

                                Please inputthe desired Python library path to use. Default is [/usr/lib/python2.7/site-packages]  直接回車

                                Using pythonlibrary path: /usr/lib/python2.7/site-packages

                                Do you wish tobuild TensorFlow with OpenCL support? [y/N]n

                                No OpenCLsupport will be enabled for TensorFlow

                                Do you wish tobuild TensorFlow with CUDA support? [y/N]n

            3.2編譯

                                $bazel build --copt=-march=native -c opt //tensorflow/tools/pip_package:build_pip_package

            3.3 生成pip安裝包

                                $ sudo mkdir -p /tmp/tensorflow/

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

                                PS:這裡我用非 /tmp 目錄時無法生成whl包,如果你也這樣那就老老實實用 /tmp 目錄吧

            3.4 安裝

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

4 測試

                好了,下面測試下吧

                                $ python

                                >>>import tensorflow as tf

                沒報錯,OK!