下载与安装
你可以使用我们提供的二进制包, 或者使用源代码, 安装 TensorFlow.
二进制安装
TensorFlow Python API 依赖 Python 2.7 版本.
在 Linux 和 Mac 下最简单的安装方式, 是使用 pip 安装.
如果在安装过程中遇到错误, 请查阅 常见问题. 为了简化安装步骤, 建议使用 virtualenv, 教程见 这里.
Ubuntu/Linux
# 仅使用 CPU 的版本
$ pip install https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.5.0-cp27-none-linux_x86_64.whl
# 开启 GPU 支持的版本 (安装该版本的前提是已经安装了 CUDA sdk)
$ pip install https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.5.0-cp27-none-linux_x86_64.whl
Mac OS X
在 OS X 系统上, 我们推荐先安装 homebrew, 然后执行 brew install python, 以便能够使用 homebrew 中的 Python 安装 TensorFlow. 另外一种推荐的方式是在 virtualenv 中安装 TensorFlow.
# 当前版本只支持 CPU
$ pip install https://storage.googleapis.com/tensorflow/mac/tensorflow-0.5.0-py2-none-any.whl
基于 Docker 的安装
我们也支持通过 Docker 运行 TensorFlow. 该方式的优点是不用操心软件依赖问题.
首先, 安装 Docker. 一旦 Docker 已经启动运行, 可以通过命令启动一个容器:
$ docker run -it b.gcr.io/tensorflow/tensorflow
该命令将启动一个已经安装好 TensorFlow 及相关依赖的容器.
运行 TensorFlow
打开一个 python 终端:
$ python
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print sess.run(hello)
Hello, TensorFlow!
>>> a = tf.constant(10)
>>> b = tf.constant(32)
>>> print sess.run(a+b)
42
>>>
从源码安装
克隆 TensorFlow 仓库
$ git clone --recurse-submodules https://github.com/tensorflow/tensorflow
--recurse-submodules 参数是必须得, 用于获取 TesorFlow 依赖的 protobuf 库.
博客介绍了TensorFlow的下载与安装方式,包括二进制安装(适用于Ubuntu/Linux和Mac OS X,依赖Python 2.7,推荐用pip和virtualenv)、基于Docker的安装(可避免软件依赖问题)以及从源码安装(需克隆TensorFlow仓库获取protobuf库)。
2863

被折叠的 条评论
为什么被折叠?



