tensorflow1.5源码安装

本文介绍了如何在特定环境中源码安装TensorFlow 1.5。首先,需要安装Bazel构建工具,接着是Python依赖包的安装。在确认源码信息后,可能会遇到因pip版本导致的安装错误,解决方案是升级pip到最新版。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

tensorflow1.5源码安装


       昨天听同学说 TensorFlow1.5.0-rc0 发布了,该版本将动态图集成到了tensorflow模块里面,不用像1.4的版本需要另外安装插件,很是激动,打算赶紧安装上手一波。但是由于才发布不久,不支持终端的pip直接安装,所以要想使用最新版本,还得自己编译源码安装。 话不多说,直接动手!(tensorflow CPU版本安装,渣渣笔记本大哭

环境:

       ubuntu14.04、python2.7


tensorflow安装环境准备

1、Bazel安装
        Bazel是一个构建工具,即一个可以运行编译和测试来组装软件的工具,跟Make、Ant、Gradle、Buck、Pants和Maven一样。Bazel官网安装教程。选择官网推荐的第一种安装方式  Use our custom APT repository (recommended)
  第一步 install JDK 8。 ubuntu14.04应该先添加PPA,终端输入命令:
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update && sudo apt-get install oracle-java8-installer
第二 句我执行时报了错,但是分开执行就通过了,即先执行
sudo apt-get update
然后执行
sudo apt-get install oracle-java8-installer
sudo apt-get install oracle-java8-installer。
第二步 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 -
第二句我执行的时候报了错,提示没有***gpg,第二天写的这个记录,具体的错忘了尴尬 。于是先把密钥下载下来吧,直接在浏览器地址栏输入https://bazel.build/bazel-release.pub.gpg,然后就可以下载该密钥文件了,然后将密钥文件拷贝到某路径path下,再执行命令
sudo apt-key add path/密钥文件名
第三步 安装Bazel,执行命令
sudo apt-get update&& sudo apt-get install bazel
实际上执行完这几步就可以了,在终端输入baz ,双击Tab键可以看到提示的命令中会出现bazel命令。

2、python依赖包安装
输入命令
sudo apt-get install python-numpy python-dev python-pip python-wheel (适用于python2.7)
3、源码信息确认
首先解压上面步骤中下载的源码包,解压包并进入到根目录
tar -zxvf tensorflow包名
cd tensorflow解压目录
./configure
出现如下配置信息:
$ cd tensorflow  # cd to the top-level directory created
$ ./configure
Please specify the location of python. [Default is /usr/bin/python]: /usr/bin/python2.7
Found possible Python library paths:
  /usr/local/lib/python2.7/dist-packages
  /usr/lib/python2.7/dist-packages
Please input the desired Python library path to use.  Default is [/usr/lib/python2.7/dist-packages]

Using python library path: /usr/local/lib/python2.7/dist-packages
Do you wish to build TensorFlow with MKL support? [y/N]
No MKL support will be enabled for TensorFlow
Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -march=native]:
Do you wish to use jemalloc as the malloc implementation? [Y/n]
jemalloc enabled
Do you wish to build TensorFlow with Google Cloud Platform support? [y/N]
No Google Cloud Platform support will be enabled for TensorFlow
Do you wish to build TensorFlow with Hadoop File System support? [y/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]
No XLA support will be enabled for TensorFlow
Do you wish to build TensorFlow with VERBS support? [y/N]
No VERBS support will be enabled for TensorFlow
Do you wish to build TensorFlow with OpenCL support? [y/N]
No OpenCL support will be enabled for TensorFlow
Do you wish to build TensorFlow with CUDA support? [y/N] N
Please specify the Cuda SDK version you want to use, e.g. 7.0. [Leave empty to default to CUDA 8.0]: 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]:
Please specify which gcc should be used by nvcc as the host compiler. [Default is /usr/bin/gcc]:
Please specify the cuDNN version you want to use. [Leave empty to default to cuDNN 6.0]: 6
Please specify the location where cuDNN 6 library is installed. Refer to README.md for more details. [Default is /usr/local/cuda]:
Please specify a list of comma-separated Cuda compute capabilities you want to build with.
You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
Please note that each additional compute capability significantly increases your build time and binary size.
[Default is: "3.5,5.2"]: 3.0
Do you wish to build TensorFlow with MPI support? [y/N]
MPI support will not be enabled for TensorFlow
Configuration finished
根据自己的需要进行选择,我没有选择cuda选项。
然后编译pip包,输入命令(会编译很长时间)
bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package
在tensorflow的根目录下执行
bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
会在/tmp/tensorflow_pkg/下生成tensorflow-1.5.0rc0-cp27-cp27mu-linux_x86_64.whl

安装tensorflow

执行命令
sudo pip install --ignore-installed --upgrade /tmp/tensorflow_pkg/tensorflow-1.5.0rc0-cp27-cp27mu-linux_x86_64.whl

安装可能会遇到如下错误(参考链接

tensorflow-1.5.0rc0-cp27-cp27mu-linux_x86_64.whl is not a supported wheel on this platform.
Storing debug log for failure in /home/xxx/.pip/pip.log

这是因为pip版本的缘故,解决办法是下载get-pip.py 文件,进入下载目录执行

$sudo python2.7 get-pip.py

再次安装即可


另启动一个终端,启动python环境,导入tensorflow包看是否成功




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值