0%

tensorflow安装

下载与安装

你可以使用我们提供的 Pip, Docker, Virtualenv, Anaconda 或 源码编译的方法安装 TensorFlow.
Pip 安装
Pip 是一个 Python 的软件包安装与管理工具.
在安装 TensorFlow 过程中要涉及安装或升级的包详见 列表
首先安装 pip (或 Python3 的 pip3 ):

Ubuntu/Linux 64-bit

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

Mac OS X

$ sudo easy_install pip
安装 TensorFlow :

Ubuntu/Linux 64-bit, CPU only, Python 2.7:

$ sudo pip install –upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.8.0-cp27-none-linux_x86_64.whl

Ubuntu/Linux 64-bit, GPU enabled, Python 2.7. Requires CUDA toolkit 7.5 and CuDNN v4.

For other versions, see “Install from sources” below.

$ sudo pip install –upgrade https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.8.0-cp27-none-linux_x86_64.whl

Mac OS X, CPU only:

$ sudo easy_install –upgrade six
$ sudo pip install –upgrade https://storage.googleapis.com/tensorflow/mac/tensorflow-0.8.0-py2-none-any.whl
如果是 Python3 :

Ubuntu/Linux 64-bit, CPU only, Python 3.4:

$ sudo pip3 install –upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.8.0-cp34-cp34m-linux_x86_64.whl

Ubuntu/Linux 64-bit, GPU enabled, Python 3.4. Requires CUDA toolkit 7.5 and CuDNN v4.

For other versions, see “Install from sources” below.

$ sudo pip3 install –upgrade https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.8.0-cp34-cp34m-linux_x86_64.whl

Mac OS X, CPU only:

$ sudo easy_install –upgrade six
$ sudo pip3 install –upgrade https://storage.googleapis.com/tensorflow/mac/tensorflow-0.8.0-py3-none-any.whl
备注:如果之前安装过 TensorFlow < 0.7.1 的版本,应该先使用 pip uninstall 卸载 TensorFlow 和 protobuf ,保证获取的是一个最新 protobuf 依赖下的安装包.
之后可以测试一下.
基于 Docker 的安装
我们也支持通过 Docker 运行 TensorFlow. 该方式的优点是不用操心软件依赖问题.
首先, 安装 Docker. 一旦 Docker 已经启动运行, 可以通过命令启动一个容器:
$ docker run -it b.gcr.io/tensorflow/tensorflow
该命令将启动一个已经安装好 TensorFlow 及相关依赖的容器.
其它镜像
默认的 Docker 镜像只包含启动和运行 TensorFlow 所需依赖库的一个最小集. 我们额外提供了 下面的容器, 该容器同样可以通过上述 docker run 命令安装:
b.gcr.io/tensorflow/tensorflow-full: 镜像中的 TensorFlow 是从源代码完整安装的, 包含了编译和运行 TensorFlow 所需的全部工具. 在该镜像上, 可以直接使用源代码进行实验, 而不需要再安装上述的任何依赖.
基于 VirtualEnv 的安装
我们推荐使用 virtualenv 创建一个隔离的容器, 来安装 TensorFlow. 这是可选的, 但是这样做能使排查安装问题变得更容易.
首先, 安装所有必备工具:

在 Linux 上:

$ sudo apt-get install python-pip python-dev python-virtualenv

在 Mac 上:

$ sudo easy_install pip # 如果还没有安装 pip
$ sudo pip install –upgrade virtualenv
接下来, 建立一个全新的 virtualenv 环境. 为了将环境建在 ~/tensorflow 目录下, 执行:
$ virtualenv –system-site-packages ~/tensorflow
$ cd ~/tensorflow
然后, 激活 virtualenv:
$ source bin/activate # 如果使用 bash
$ source bin/activate.csh # 如果使用 csh
(tensorflow)$ # 终端提示符应该发生变化
在 virtualenv 内, 安装 TensorFlow:
(tensorflow)$ pip install –upgrade <$url_to_binary.whl>
接下来, 使用类似命令运行 TensorFlow 程序:
(tensorflow)$ cd tensorflow/models/image/mnist
(tensorflow)$ python convolutional.py

当使用完 TensorFlow

(tensorflow)$ deactivate # 停用 virtualenv

$ # 你的命令提示符会恢复原样
基于 Anaconda 的安装
Anaconda 是一个集成许多第三方科学计算库的 Python 科学计算环境,Anaconda 使用 conda 作为自己的包管理工具,同时具有自己的计算环境,类似 Virtualenv.
和 Virtualenv 一样,不同 Python 工程需要的依赖包,conda 将他们存储在不同的地方。 TensorFlow 上安装的 Anaconda 不会对之前安装的 Python 包进行覆盖.
安装 Anaconda
建立一个 conda 计算环境
激活环境,使用 conda 安装 TensorFlow
安装成功后,每次使用 TensorFlow 的时候需要激活 conda 环境
安装 Anaconda :
参考 Anaconda 的下载页面的指导
建立一个 conda 计算环境名字叫tensorflow:

Python 2.7

$ conda create -n tensorflow python=2.7

Python 3.4

$ conda create -n tensorflow python=3.4
激活tensorflow环境,然后使用其中的 pip 安装 TensorFlow. 当使用easy_install使用–ignore-installed标记防止错误的产生。
$ source activate tensorflow
(tensorflow)$ # Your prompt should change

Ubuntu/Linux 64-bit, CPU only, Python 2.7:

(tensorflow)$ pip install –ignore-installed –upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.8.0rc0-cp27-none-linux_x86_64.whl

Ubuntu/Linux 64-bit, GPU enabled, Python 2.7. Requires CUDA toolkit 7.5 and CuDNN v4.

For other versions, see “Install from sources” below.

(tensorflow)$ pip install –ignore-installed –upgrade https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.8.0rc0-cp27-none-linux_x86_64.whl

Mac OS X, CPU only:

(tensorflow)$ pip install –ignore-installed –upgrade https://storage.googleapis.com/tensorflow/mac/tensorflow-0.8.0rc0-py2-none-any.whl
对于 Python 3.x :
$ source activate tensorflow
(tensorflow)$ # Your prompt should change

Ubuntu/Linux 64-bit, CPU only, Python 3.4:

(tensorflow)$ pip install –ignore-installed –upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.8.0rc0-cp34-cp34m-linux_x86_64.whl

Ubuntu/Linux 64-bit, GPU enabled, Python 3.4. Requires CUDA toolkit 7.5 and CuDNN v4.

For other versions, see “Install from sources” below.

(tensorflow)$ pip install –ignore-installed –upgrade https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.8.0rc0-cp34-cp34m-linux_x86_64.whl

Mac OS X, CPU only:

(tensorflow)$ pip install –ignore-installed –upgrade https://storage.googleapis.com/tensorflow/mac/tensorflow-0.8.0rc0-py3-none-any.whl
conda 环境激活后,你可以测试
当你不用 TensorFlow 的时候,关闭环境:
(tensorflow)$ source deactivate

$ # Your prompt should change back
再次使用的时候再激活 :-)
$ source activate tensorflow
(tensorflow)$ # Your prompt should change.

Run Python programs that use TensorFlow.

When you are done using TensorFlow, deactivate the environment.

(tensorflow)$ source deactivate