archlinux下源碼編譯tensorflow
1. 環境準備
$ sudo pacman -S bazel
2. 下載源碼
獲取源碼
$ git clone https://github.com/tensorflow/tensorflow.git
下載miniconda
目前版本下,python3.6使用就很可以,不下最新的python3.7的miniconda,下載後
$ bash Miniconda3-4.5.1-Linux-x86_64
安裝完成後千萬不要pip install tensorflow 或者 conda install tensorflow,這樣會安裝未編譯的版本,最後就算是卸載,也要把一些依賴卸載,乾脆別裝
3. 編譯
$ cd (path)/tensorflow (path)爲你git clone下的目錄
$ ./configue (之後一路下去都選no, 其他的默認就可以了)
編譯
$ bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package
編譯成功後的信息
At global scope:
cc1plus: warning: unrecognized command line option '-Wno-self-assign'
Target //tensorflow/tools/pip_package:build_pip_package up-to-date:
bazel-bin/tensorflow/tools/pip_package/build_pip_package
INFO: Elapsed time: 9402.576s, Critical Path: 397.05s
INFO: 1944 processes: 1944 local.
INFO: Build completed successfully, 2104 total actions
生成whl文件
就在tensorflow 目錄下
$ bazel-bin/tensorflow/tools/pip_package/build_pip_package ~/tensorflow_pkg
~/tensorflow_pkg是輸出目錄,之後.wheel文件就在該目錄下, 運行輸出如下:
2018年 12月 28日 星期五 14:21:09 CST : === Preparing sources in dir: /tmp/tmp.BVOrF1c3FU
~/App/tensorflow ~/App/tensorflow
~/App/tensorflow
2018年 12月 28日 星期五 14:21:27 CST : === Building wheel
warning: no files found matching '*.pyd' under directory '*'
warning: no files found matching '*.pd' under directory '*'
warning: no files found matching '*.dll' under directory '*'
warning: no files found matching '*.lib' under directory '*'
warning: no files found matching '*.h' under directory 'tensorflow/include/tensorflow'
warning: no files found matching '*' under directory 'tensorflow/include/Eigen'
warning: no files found matching '*.h' under directory 'tensorflow/include/google'
warning: no files found matching '*' under directory 'tensorflow/include/third_party'
warning: no files found matching '*' under directory 'tensorflow/include/unsupported'
2018年 12月 28日 星期五 14:22:08 CST : === Output wheel file is in: /home/lee/tensorflow_pkg
4. 安裝
cd ~/tensorflow_pkg
pip install tensorflow-1.12.0-cp36-cp36m-linux_x86_64.whl
這裏會自動下載依賴,完成