在ubuntu 14.04上源码编译Tensorflow

1. 安装Bazel自动化编译工具

sudo add-apt-repository ppa:webupd8team/java

sudo apt-get update && sudo apt-get install oracle-java8-installer

echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list

curl https://bazel.build/bazel-release.pub.gpg|sudo apt-key add -

sudo apt-get update && sudo apt-get install bazel


2. 下载tensor源码

git clone --recurse-submodules https://github.com/tensorflow/tensorflow

3. 配置

./configure


4. 编译

sudo apt-get install python-numpy

sudo apt-get install python-dev

bazel build --config=opt  //tensorflow/tools/pip_package:build_pip_package


5. 生成安装包

./bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg



后记:

编译过程中可能出现以下错误:

Traceback (most recent call last):

File "/home/tensorflow/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/examples/image_retraining/retrain.py", line 108, in

import tensorflow as tf

File "/home/tensorflow/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/__init__.py", line 24, in

from tensorflow.python import *

File "/home/tensorflow/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/python/__init__.py", line 63, in

from tensorflow.python.framework.framework_lib import *

File "/home/tensorflow/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/python/framework/framework_lib.py", line 102, in

from tensorflow.python.framework.importer import import_graph_def

File "/home/tensorflow/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/python/framework/importer.py", line 30, in

from tensorflow.python.framework import function

File "/home/tensorflow/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/python/framework/function.py", line 34, in

from tensorflow.python.ops import variable_scope as vs

File "/home/tensorflow/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/python/ops/variable_scope.py", line 191, in

"""

AttributeError: 'int' object attribute '__doc__' is read-only


解决办法是:

1. 卸载之前安装的enum模块

#sudo pip uninstall enum

2. 安装新的enum模块

#sudo apt-get install python-enum34

你可能感兴趣的:(在ubuntu 14.04上源码编译Tensorflow)