本節書摘來異步社群《tensorflow技術解析與實戰》一書中的第2章,第2.4節,作者:李嘉璇,更多章節内容可以通路雲栖社群“異步社群”公衆号檢視。
從源代碼編譯安裝,需要使用bazel編譯工具。我們先安裝bazel工具。在需要依賴的jdk 8配好之後,在mac筆記本上直接執行下面指令,安裝版本是0.4.4:
tensorflow-1.1.0 ./configure
please specify the location of python.[default is /usr/local/bin/python]:
please specify optimization flags to use during compilation [default is -march=native]:
do you wish to use jemalloc as the malloc implementation? (linux only) [y/n]
jemalloc enabled on linux
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
found possible python library paths:
/usr/local/cellar/python/2.7.12_2/frameworks/python.framework/versions/2.7/lib/python2.7/site-packages
/library/python/2.7/site-packages
please input the desired python library path to use. default is [/usr/local/cellar/ python/2.7.12_2/frameworks/python.framework/versions/2.7/lib/python2.7/site-packages]
using python library path: /usr/local/cellar/python/2.7.12_2/frameworks/python. framework/versions/2.7/lib/python2.7/site-packages
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]
no cuda support will be enabled for tensorflow
configuration finished
bazel build --local_resources 2048,4,1.0 -c opt //tensorflow/tools/pip_package:build_ pip_package
bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
然後進入/tmp/tensorflow_pkg,可以看到生成的檔案tensorflow-1.1.0-cp27-c
pip install /tmp/tensorflow_pkg/tensorflow-1.1.0-cp27-cp27m-macosx_10_12_intel.whl<code>`</code>
使用gpu版本的編譯需要配置中選擇使用cuda,然後填寫對應的cuda sdk版本等,其他步驟均相同。