您的位置:首页 > 其它

tensorflow源码安装过程记录(ubuntu16、基于CPU)

2018-01-26 10:01 846 查看
Ubuntu16.04安装地址:

下载连接:

64位:

http://releases.ubuntu.com/16.04/ubuntu-16.04-desktop-amd64.iso

32位:

http://releases.ubuntu.com/16.04/ubuntu-16.04-desktop-i386.iso

参考博客http://blog.csdn.net/a446712385/article/details/79149977

1.安装git,下载tensorflow源码

安装git:

sudo apt install git

克隆 TensorFlow 仓库(参考http://wiki.jikexueyuan.com/project/tensorflow-zh/get_started/os_setup.html

在终端输入以下代码:

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

下载后可看到tensorflow的文件

2.安装Bazel对tensorflow进行源码编译

参考https://docs.bazel.build/versions/master/install.html#1-install-jdk-8-1

2.1传统的API安装

1. Install JDK 8

Install JDK 8 by using:

sudo apt-get install openjdk-8-jdk

Add Bazel distribution URI as a package source (one time setup)

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 -

If you want to install the testing version of Bazel, replace stable with testing.

Install and update Bazel

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

Once installed, you can upgrade to a newer version of Bazel with:

sudo apt-get upgrade bazel

此处安装成功之后可在终端输入bazel得到



3.安装其他依赖项

3.1安装python2.7与python3.5(系统自带)

//For Python 2.7:

sudo apt-get install python-numpy swig python-dev python-wheel

此处出现多处依赖相互干扰的情况无法正常安装,建议分别安装

如 sudo apt-get install python-numpy

sudo apt-get python-numpy

sudo apt-get swig

etc….

或者也可尝试使用sudo pip install python-numpy等

//For Python 3.x:

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

4.配置及安装tensorflow

1)配置

终端输入以下命令:

cd tensorflow

./configure



根据需要选择y/N,此处是基于cpu编译,因而无需选择CUDA等环境进行编译

2)安装

创建 pip 包并安装(以下是官网提供的代码)

bazel build -c opt //tensorflow/tools/pip_package:build_pip_package

以上步骤会出现错误,由于该处的编译是基于python2.7因而需要安装python2版本依赖的库

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

pip install /tmp/tensorflow_pkg/tensorflow-0.5.0-cp27-none-linux_x86_64.whl(此文件为bazel编译生成的whl文件)

(以上步骤仍然会报错,是由于所称从的wheel文件是cp35,因而需要使用基于python3安装的pip3进行操作)

5.测试

输入python3

输入import tensorflow as tf

可以正常加载即可
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息