ubuntu 16.04下tensorflow的安装
ubuntu 16.04下tensorflow的安装
江桃人 发表于8个月前
ubuntu 16.04下tensorflow的安装
  • 发表于 8个月前
  • 阅读 400
  • 收藏 0
  • 点赞 1
  • 评论 1

新睿云服务器60天免费使用,快来体验!>>>   

摘要: 操作系统:Ubuntu16.04 tensorflow version:0.9 cuda version: 8.0 cudnn version:5.0 bazel version:0.3.1

安装说明

    因为是首次安装学习tensorflow,1.0之后的没有models,所以安装r0.9。

安装过程

  • bazel安装
  1.  install dk8
    sudo apt-get install openjdk-8-jdk

     

  2.  clone bazel sourcecode
    git clone https://github.com/bazelbuild/bazel.git

     

  3.  进入bazel目录
    cd bazel

     

  4.  切换tags 0.3.1
    git checkout tags/0.3.1

     

  5.  编译
    ./compile.sh

     

  6.  编辑~/.bashrc文件
    vim ~/.bashrc

     

  7.  添加bazel的执行文件到PATH
    PATH=~/work/opensource/bazel/output/:PATH

     

  8.  更新文件配置文件使其生效
    source ~/.bashrc

     

  • CUDA安装
  1.  进入https://developer.nvidia.com/cuda-downloads
  2.  选择需要下载的cuda,我下载的是cuda-repo-ubuntu1604-8-0-local-ga2_8.0.61-1_amd64.deb
  3.  解压安装包
    sudo dpkg -i xxxx.deb

     

  4.  更新
    sudo apt-get update

     

  5.  安装
    sudo apt-get install cuda

     

  • CUDNN下载安装
  1.  进入下载页,注册
  2.  下载对应的cudnn,这里我下载了cudnn-8.0-linux-x64-v5.0-ga.tgz,建议下载这个
  3.  解压
    tar xvzf cudnn-8.0-linux-x64-v5.0.tgz

     

  4.  复制.h文件到cuda的include
    sudo cp include/cudnn.h /usr/local/cuda/include

     

  • 安装pip
  1.  下载
    wget "https://pypi.python.org/packages/source/p/pip/pip-1.5.4.tar.gz#md5=834b2904f92d46aaa333267fb1c922bb" --no-check-certificate

     

  2.  解压
    tar -xzvf pip-1.5.4.tar.gz

     

  • 其他一些工具安装
  1. apt-get install pkg-config zip g++ zlib1g-dev unzip
  2. sudo apt-get install python-numpy swig python-dev python-wheel
  • tensorflow下载安装
  1.  clone sourcecode
     git clone --recurse-submodules https://github.com/tensorflow/tensorflow

     

  2.  切换分支
     git checkout -b r0.9 remotes/orgin/r0.9

     

  3.  配置
     ./configuration
        a. select python [enter]
        b. google cloud support [f]
        c. gpu support [Y]
        d. gcc [enter]
        e. cuda sdk [8.0]
        f. cudnn version [5]
        g. cudnn paht [enter]

     

  4.  bazel编译
    bazel build -c opt --config=cuda //tensorflow/tools/pip_package:build_pip_package

     

  5.  打包
    bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg

     

  6.  安装
    sudo pip install /tmp/tensorflow_pkg/tensorflow-0.9.0-py2-none-any.whl

     

注意事项

  • tensorflow,bazel,cuda的对应关系,否则会编译通不过的问题。eg:the specified --crosstool_top '//third_party/gpus/crosstoll:crosstool' is not a valid cc_toolchain_suite rule.
  • 这里的cudnn版本应该选择5.0, 否则0.9下面的model会报错,eg:if using a binary install, upgarde youe cudnn library to match.

 

--------------------------2017-10-14 更新------安装Python3.6 对应版本---------------------------------------------

安装v1.4.0-rc0版

  • 切换tag
    git checkout tags/v1.4.0-rc0
  • 此时提示:

You have bazel 0.3.1-2017-06-08 (@1f49b6b) installed.

Please upgrade your bazel installation to version 0.5.4 or higher to build TensorFlow!
Configuration finished”

  • 切换bazel tag到0.6.1,编译,报错“

    🍃  Building Bazel from scratch
    ERROR: Must specify PROTOC if not bootstrapping from the distribution artifact

    --------------------------------------------------------------------------------
    NOTE: This failure is likely occuring if you are trying to bootstrap bazel from
    a developer checkout. Those checkouts do not include the generated output of
    the protoc compiler (as we prefer not to version generated files).

    * To build a developer version of bazel, do

        bazel build //src:bazel

    * To bootstrap your first bazel binary, please download a dist archive from our
      release page at https://github.com/bazelbuild/bazel/releases and run
      compile.sh on the unpacked archive.

    The full install instructions to install a release version of bazel can be found
    at https://docs.bazel.build/install-compile-source.html
    For a rationale, why the bootstrap process is organized in this way, see
    https://bazel.build/designs/2016/10/11/distribution-artifact.html
    --------------------------------------------------------------------------------

  • 去bazel官网,下载0.6.1的release源码,https://github.com/bazelbuild/bazel/releases
  • 解压并编译
    unzip bazel-0.6.1-dist.zip
    ./compile.sh

    成功,提示Build successful! Binary is here: /home/--/work/opensource/bazel-0.6.1/output/bazel

  • 添加bazel的执行文件到PATH,并更新配置文件

  • 检查bazel版本
bazel version
  • 根据情况配置编译项
./configure

漫长的等待后,出现了

Target //tensorflow/tools/pip_package:build_pip_package failed to build

  • 查看具体的错误原因
bazel build -c opt --config=cuda --verbose_failures //tensorflow/tools/pip_package:build_pip_package

错误:

crosstool_wrapper_driver_is_not_gcc failed: error executing command

'::cudnnSetRNNDescriptor_v6' has not been declared

  • 打赏
  • 点赞
  • 收藏
  • 分享
共有 人打赏支持
粉丝 5
博文 15
码字总数 15700
评论 (1)
江桃人
最近由于课程压力,还没有编译通过最新的,自己给自己留言,希望别忘了,等不忙的时候一定源码编译通过,小肥仔加油。
×
江桃人
穷学生,求打赏。
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: