源码编译安装tensorflow

由于公司要在飞腾、龙芯上安装、因此源码编译tensorflow,但编译tensorflow要用bazel工具包来进行编译,因此要首先编译安装bazel。

因为tensorflow是基于python的一个模块,因此首先下载python等

下载 python-pip、enum、python-enum、python-numpy、python-dev、python-wheel、swig

直接下载升级,少走弯路

pip需要升级                 pip install -U pip
缺少enum 会报错       apt-get install enum python-enum

编译需要联网,能访问github.com  、 bazel-mirror.storage.googleapis.com  否则解析不到,报错

root@3ddff7ac827a:/opt/tensorflow/tensorflow-r1.7# bazel build --config opt //tensorflow/tools/pip_package:build_pip_package

编译成功的显示
Target //tensorflow/tools/pip_package:build_pip_package up-to-date:
  bazel-bin/tensorflow/tools/pip_package/build_pip_package
INFO: Elapsed time: 5587.884s, Critical Path: 90.02s
INFO: 4554 processes, local.
INFO: Build completed successfully, 5033 total actions


编译完成后生成.whl安装包
root@3ddff7ac827a:/opt/tensorflow/tensorflow-r1.7# bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
Mon Jul 9 02:45:32 UTC 2018 : === Using tmpdir: /tmp/tmp.UOcDG24o5A
/opt/tensorflow/tensorflow-r1.7/bazel-bin/tensorflow/tools/pip_package/build_pip_package.runfiles /opt/tensorflow/tensorflow-r1.7
/opt/tensorflow/tensorflow-r1.7
/tmp/tmp.UOcDG24o5A /opt/tensorflow/tensorflow-r1.7
Mon Jul 9 02:45:34 UTC 2018 : === Building wheel
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 '*' under directory 'tensorflow/include/external'
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'
/opt/tensorflow/tensorflow-r1.7
Mon Jul 9 02:46:04 UTC 2018 : === Output wheel file is in: /tmp/tensorflow_pkg


安装tmp目录下的tensorflow
root@3ddff7ac827a:/tmp/tensorflow_pkg# ls
tensorflow-1.7.1-cp27-cp27mu-linux_x86_64.whl
root@3ddff7ac827a:/tmp/tensorflow_pkg# pip install tensorflow-1.7.1-cp27-cp27mu-linux_x86_64.whl
Processing ./tensorflow-1.7.1-cp27-cp27mu-linux_x86_64.whl
Requirement already satisfied: mock>=2.0.0 in /usr/local/lib/python2.7/dist-packages (from tensorflow==1.7.1) (2.0.0)
Collecting grpcio>=1.8.6 (from tensorflow==1.7.1)
  Downloading https://files.pythonhosted.org/packages/fa/53/685b9d68e5734cf8e2d13b2d4d29e6cede94714b665019a5627a623b3e21/grpcio-1.13.0-cp27-cp27mu-manylinux1_x86_64.whl (9.0MB)
    100% |################################| 9.0MB 727kB/s
Collecting enum34>=1.1.6 (from tensorflow==1.7.1)
  Downloading https://files.pythonhosted.org/packages/c5/db/e56e6b4bbac7c4a06de1c50de6fe1ef3810018ae11732a50f15f62c7d050/enum34-1.1.6-py2-none-any.whl
Requirement already satisfied: numpy>=1.13.3 in /usr/local/lib/python2.7/dist-packages (from tensorflow==1.7.1) (1.13.3)
Collecting termcolor>=1.1.0 (from tensorflow==1.7.1)
  Downloading https://files.pythonhosted.org/packages/8a/48/a76be51647d0eb9f10e2a4511bf3ffb8cc1e6b14e9e4fab46173aa79f981/termcolor-1.1.0.tar.gz
Requirement already satisfied: backports.weakref>=1.0rc1 in /usr/local/lib/python2.7/dist-packages (from tensorflow==1.7.1) (1.0.post1)
Collecting absl-py>=0.1.6 (from tensorflow==1.7.1)
  Downloading https://files.pythonhosted.org/packages/57/8d/6664518f9b6ced0aa41cf50b989740909261d4c212557400c48e5cda0804/absl-py-0.2.2.tar.gz (82kB)
    100% |################################| 92kB 556kB/s
Requirement already satisfied: wheel in /usr/local/lib/python2.7/dist-packages (from tensorflow==1.7.1) (0.30.0)
Collecting tensorboard<1.8.0,>=1.7.0 (from tensorflow==1.7.1)
  Downloading https://files.pythonhosted.org/packages/6e/5b/18f50b69b8af42f93c47cd8bf53337347bc1974480a10de51fdd7f8fd48b/tensorboard-1.7.0-py2-none-any.whl (3.1MB)
    100% |################################| 3.1MB 177kB/s
Requirement already satisfied: six>=1.10.0 in /usr/local/lib/python2.7/dist-packages (from tensorflow==1.7.1) (1.11.0)
Collecting gast>=0.2.0 (from tensorflow==1.7.1)
  Downloading https://files.pythonhosted.org/packages/5c/78/ff794fcae2ce8aa6323e789d1f8b3b7765f601e7702726f430e814822b96/gast-0.2.0.tar.gz
Requirement already satisfied: protobuf>=3.4.0 in /usr/local/lib/python2.7/dist-packages (from tensorflow==1.7.1) (3.4.0)
Collecting astor>=0.6.0 (from tensorflow==1.7.1)
  Downloading https://files.pythonhosted.org/packages/35/6b/11530768cac581a12952a2aad00e1526b89d242d0b9f59534ef6e6a1752f/astor-0.7.1-py2.py3-none-any.whl
Requirement already satisfied: funcsigs>=1; python_version < "3.3" in /usr/local/lib/python2.7/dist-packages (from mock>=2.0.0->tensorflow==1.7.1) (1.0.2)
Requirement already satisfied: pbr>=0.11 in /usr/local/lib/python2.7/dist-packages (from mock>=2.0.0->tensorflow==1.7.1) (3.1.1)
Collecting futures>=2.2.0 (from grpcio>=1.8.6->tensorflow==1.7.1)
  Downloading https://files.pythonhosted.org/packages/2d/99/b2c4e9d5a30f6471e410a146232b4118e697fa3ffc06d6a65efde84debd0/futures-3.2.0-py2-none-any.whl
Requirement already satisfied: bleach==1.5.0 in /usr/local/lib/python2.7/dist-packages (from tensorboard<1.8.0,>=1.7.0->tensorflow==1.7.1) (1.5.0)
Requirement already satisfied: markdown>=2.6.8 in /usr/local/lib/python2.7/dist-packages (from tensorboard<1.8.0,>=1.7.0->tensorflow==1.7.1) (2.6.9)
Requirement already satisfied: html5lib==0.9999999 in /usr/local/lib/python2.7/dist-packages (from tensorboard<1.8.0,>=1.7.0->tensorflow==1.7.1) (0.9999999)
Requirement already satisfied: werkzeug>=0.11.10 in /usr/local/lib/python2.7/dist-packages (from tensorboard<1.8.0,>=1.7.0->tensorflow==1.7.1) (0.12.2)
Requirement already satisfied: setuptools in /usr/local/lib/python2.7/dist-packages (from protobuf>=3.4.0->tensorflow==1.7.1) (36.6.0)
Building wheels for collected packages: termcolor, absl-py, gast
  Running setup.py bdist_wheel for termcolor ... done
  Stored in directory: /root/.cache/pip/wheels/7c/06/54/bc84598ba1daf8f970247f550b175aaaee85f68b4b0c5ab2c6
  Running setup.py bdist_wheel for absl-py ... done
  Stored in directory: /root/.cache/pip/wheels/a0/f8/e9/1933dbb3447ea6ef57062fd5461cb118deb8c2ed074e8344bf
  Running setup.py bdist_wheel for gast ... done
  Stored in directory: /root/.cache/pip/wheels/9a/1f/0e/3cde98113222b853e98fc0a8e9924480a3e25f1b4008cedb4f
Successfully built termcolor absl-py gast
Installing collected packages: futures, enum34, grpcio, termcolor, absl-py, tensorboard, gast, astor, tensorflow
  Found existing installation: tensorflow 1.3.0
    Uninstalling tensorflow-1.3.0:
      Successfully uninstalled tensorflow-1.3.0
Successfully installed absl-py-0.2.2 astor-0.7.1 enum34-1.1.6 futures-3.2.0 gast-0.2.0 grpcio-1.13.0 tensorboard-1.7.0 tensorflow-1.7.1 termcolor-1.1.0

编译成功。

此编译过程是在x86服务商编译完成的,本次就到这里,看飞腾、龙芯编译过程,请看下一篇!!!

你可能感兴趣的:(tensorflow)