Ubuntu 16.04 安装CPU版tensorflow

1.下载tensorflow源码:

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

2.安装JDK

$ sudo apt-get install openjdk-8-jdk

3.安装bazel(apt):

$ 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

安装bazel(binary installer):

$ sudo apt-get install pkg-config zip g++zlib1g-dev unzip python

Download bazel installer: https://github.com/bazelbuild/bazel/releases

$ chmod +x bazel--installer-linux-x86_64.sh

$ ./bazel--installer-linux-x86_64.sh --user

$ vim ~/.bashrc

添加:export PATH="$PATH:$HOME/bin"

4.安装依赖库:

# for Python 2.7

$ sudo apt-get install python-numpypython-dev python-pip python-wheel

# for Python 3.x

$ sudo apt-get install python3-numpy python3-dev python3-pip python3-wheel

5.配置:

$ cd tensorflow*

$ ./configure

安装命令行提示,逐个设置编译选项(最简单的版本一路默认,选no)

6.编译:

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

7.生成whl包:

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

8.安装生成的包:

$ sudo pip install /tmp/tensorflow_pkg/tensorflow-*.whl

9.重启:

$ sudo reboot


备注:

遇到“The following packages have unmet dependencies:”的问题:

$ sudo apt-get clean

$ sudo apt-get autoclean

$ sudo apt-get  -f install

$ sudo dpkg --configure -a

$ sudo apt-get -f install


Bazel卸载

$ sudo apt-get --purge remove bazel

$ sudo apt autoremove

Tensorflow修改源代码后重新编译

#!/bin/bash

sudo pip uninstall tensorflow -y

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

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

sudo pip install /tmp/tensorflow_pkg/tensorflow-*.whl

查看tensorflow版本和路径信息:

python环境执行:

>>> import tensorflow as tf

>>> tf.__version__

输出tensorflow版本信息

>>>tf.__path__

输出tensorflow安装路径

你可能感兴趣的:(Ubuntu 16.04 安装CPU版tensorflow)