ubuntu16.04 源码方法安装tensorflow

参考博客:http://blog.csdn.net/zhaoyu106/article/details/52793183/,
http://blog.csdn.net/u010900574/article/details/52201808
由于我之前已经配置过cuda8.0和cudnn5.1.10所以不用安装了
1、安装bazel
点击链接: installer for your system,跳转到Bazel的下载页面:
下载bazel-0.7.0-installer-linux-x86_64.sh到桌面,下载最新版的,不用和我的一致,然后在terminal中输入以下命令
cd  /home/***(自己的用户名)/Desktop/###(这个命令意思是找到刚刚我们用U盘传过来的文件)
chmod +x PATH_TO_INSTALL.SH #对.sh文件授权
./PATH_TO_INSTALL.SH --user #运行.sh文件

 2、安装第三方库

在terminal中输入以下命令

sudo apt-get install python-numpy swig python-dev python-wheel #安装第三方库
sudo apt-get install git
git clone git://github.com/numpy/numpy.git numpy 

 3、安装tensorflow

在terminal中输入以下命令

git clone https://github.com/tensorflow/tensorflow

 在terminal中输入以下命令:

cd ~/tensorflow #切换到tensorflow文件夹
./configure #执行configure文件

 

Do you wish to use jemalloc as the malloc implementation? [Y/n] y
jemalloc enabled
Do you wish to build TensorFlow with Google Cloud Platform support? [y/N] n
No Google Cloud Platform support will be enabled for TensorFlow
Do you wish to build TensorFlow with Hadoop File System support? [y/N] 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] n
No XLA JIT support will be enabled for TensorFlow
Found possible Python library paths:
  /usr/lib/python2.7/site-packages
  /usr/lib64/python2.7/site-packages
Please input the desired Python library path to use.  Default is [/usr/lib/python2.7/site-packages]

Using python library path: /usr/lib/python2.7/site-packages
Do you wish to build TensorFlow with OpenCL support? [y/N] n
No OpenCL support will be enabled for TensorFlow
Do you wish to build TensorFlow with CUDA support? [y/N] y
CUDA support will be enabled for TensorFlow
Please specify which gcc should be used by nvcc as the host compiler. [Default is /usr/bin/gcc]: 
Please specify the CUDA SDK version you want to use, e.g. 7.0. [Leave empty to use system default]: 8.0
Please specify the location where CUDA 8.0 toolkit is installed. Refer to README.md for more details. [Default is /usr/local/cuda]: /usr/local/cuda-8.0

 4创建pip

在tensorflow的根目录下,在terminal中输入以下命令:
bazel build -c opt //tensorflow/tools/pip_package:build_pip_package
bazel build -c opt --config=cuda //tensorflow/tools/pip_package:build_pip_package
bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
sudo pip install /home/***(你自己的用户名)/Desktop/tensorflow-0.10.0-cp2-none-any.whl

 tensorflow-0.10.0-cp2-none-any.whl要根据你下载的文件名有所更改。

5、设置tensorflow环境

 

bazel build -c opt //tensorflow/tools/pip_package:build_pip_package
 # To build with GPU support:
bazel build -c opt --config=cuda //tensorflow/tools/pip_package:build_pip_package
mkdir _python_build
cd _python_build
ln -s ../bazel-bin/tensorflow/tools/pip_package/build_pip_package.runfiles/org_tensorflow/* .
ln -s ../tensorflow/tools/pip_package/* .
python setup.py develop

 6、tensorflow测试

 

$ python

>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print sess.run(hello)
Hello, TensorFlow!
>>> a = tf.constant(10)
>>> b = tf.constant(32)
>>> print sess.run(a+b)
42
>>>

 大功告成

出现的错误
操作

bazel build -c opt --config=cuda //tensorflow/cc:tutorials_example_trainer

 报错

ERROR: /home/yaroslavvb/tensorflow.git/tensorflow/tensorflow/core/kernels/BUILD:1080:1: undeclared inclusion(s) in rule '//tensorflow/core/kernels:cwise_op_gpu': 
this is missing dependency dependency for following files included by 'tensorflow/core/kernels/cwise_op_gpu_floor.cu.cc':
  '/usr/local/cuda-8.0/include/cuda_runtime.h'
  '/usr/local/cuda-8.0/include/host_config.h'
  '/usr/local/cuda-8.0/include/builtin_types.h'
  '/usr/local/cuda-8.0/include/device_types.h'
  '/usr/local/cuda-8.0/include/host_defines.h'
  '/usr/local/cuda-8.0/include/driver_types.h'
  '/usr/local/cuda-8.0/include/surface_types.h'
  '/usr/local/cuda-8.0/include/texture_types.h'

 可以进入tensorflow/third_party/gpus/crosstool/目录,打开CROSSTOOL文件,搜索cxx_builtin_include_directory,应该有三行,在下面添加行如下
cxx_builtin_include_directory: "/usr/local/cuda-8.0/include"

如果出现的错误是类似的,只要将cxx_builtin_include_directory: "/usr/local/cuda-8.0/include"的文件路径改一下就可以了,亲测有效

再次运行上一步的命令,应该就没问题了。

 

    原文作者:深度学习1
    原文地址: https://www.cnblogs.com/lindaxin/p/7797477.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞