源码安装 tensorFlow
Posted 血影雪梦
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了源码安装 tensorFlow相关的知识,希望对你有一定的参考价值。
1,相关下载
1.1 下载tensorFlow
wget https://github.com/tensorflow/tensorflow/archive/v1.0.0-rc0.tar.gz
1.2 下载bazel
在该网页
https://github.com/bazelbuild/bazel/releases
找到与你的系统对应的bazel-$version-installer-$os.sh
note:尽量下最新的。
PS:我下的是bazel-0.4.5-installer-linux-x86_64.sh
2,安装依赖包
2.1 python的依赖包
这个就不列举了,我这边的环境曾经弄个caffe,所以也不知道具体需要哪些,总之yum install python-pip python-dev python-virtualenv,之后提示缺什么就用pip安装什么就好。
2.2 bazel
一般直接
./bazel-0.4.5-installer-linux-x86_64.sh --user
就可以了,不过我想安装在自己的目录下方便管理,所以使用了下面的命令:
mkdir-p /home/spark/xs/tf/bazel/bin
./bazel-0.4.5-installer-linux-x86_64.sh--prefix=/home/spark/xs/tf/bazel --bin=/home/spark/xs/tf/bazel/bin --base=/home/spark/xs/tf/bazel/.bazel--bazelrc=/home/spark/xs/tf/bazel/.bazelrc
然后把/home/spark/xs/tf/bazel/bin添加到环境变量PATH里
3,安装tensorFlow
进入tensorFlow目录
3.1配置
$ ./configure
下面是我的选项,因为我不用GPU,所以最后两个选的n,如果你用的话要选y。
Please specifythe location of python. [Default is /usr/bin/python]:直接回车
Please specifyoptimization flags to use during compilation when bazel option"--config=opt" is specified [Default is -march=native]:直接回车
Do you wish touse jemalloc as the malloc implementation? [Y/n]直接回车
jemallocenabled
Do you wish tobuild TensorFlow with Google Cloud Platform support? [y/N]n (不需要google云支持)
No GoogleCloud Platform support will be enabled for TensorFlow
Do you wish tobuild TensorFlow with Hadoop File System support? [y/N]直接回车
No Hadoop FileSystem support will be enabled for TensorFlow
Do you wish to build TensorFlowwith the XLA just-in-time compiler (experimental)? [y/N]直接回车
No XLA supportwill be enabled for TensorFlow
Found possiblePython library paths:
/usr/lib/python2.7/site-packages
/usr/lib64/python2.7/site-packages
Please inputthe desired Python library path to use. Default is [/usr/lib/python2.7/site-packages] 直接回车
Using pythonlibrary path: /usr/lib/python2.7/site-packages
Do you wish tobuild TensorFlow with OpenCL support? [y/N]n
No OpenCLsupport will be enabled for TensorFlow
Do you wish tobuild TensorFlow with CUDA support? [y/N]n
3.2编译
$bazel build --copt=-march=native -c opt //tensorflow/tools/pip_package:build_pip_package
3.3 生成pip安装包
$ sudo mkdir -p /tmp/tensorflow/
$ sudo bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow/
PS:这里我用非 /tmp 目录时无法生成whl包,如果你也这样那就老老实实用 /tmp 目录吧
3.4 安装
$sudo pip install /tmp/tensorflow/tensorflow-1.0.1-cp27-cp27mu-linux_x86_64.whl
4 测试
好了,下面测试下吧
$ python
>>>import tensorflow as tf
没报错,OK!
以上是关于源码安装 tensorFlow的主要内容,如果未能解决你的问题,请参考以下文章
解决Tensorflow源码安装的之后TensorBoard 无法使用的问题
ubuntu16.04 源码安装Python3.7 并在此基础上安装Tensorflow (确保Tensorflow计算框架与系统的彻底隔离)