TensorFlow

Anaconda 可以轻松安装 TensorFlow,从而支持您的数据科学、机器学习和人工IntelliJ工作流。

此页面展示了如何 使用 Anaconda 和 Miniconda 中包含的 conda 包管理器安装TensorFlow

带有 conda 的 TensorFlow 支持 64 位 Windows 7 或更高版本、64 位 Ubuntu Linux 14.04 或更高版本、64 位 CentOS Linux 6 或更高版本以及 macOS 10.10 或更高版本。

所有操作系统的说明都相同。不需要或命令。apt installyum install


安装 TensorFlow

  1. 下载并安装Anaconda或较小的Miniconda

  2. 在 Windows 上,打开“开始”菜单并打开 Anaconda 命令提示符。在 macOS 或 Linux 上打开一个终端窗口。在 macOS 或 Linux 上使用默认的 bash shell。

  3. 为您的 TensorFlow 环境选择一个名称,例如“tf”。

  4. 要安装当前版本的 CPU-only TensorFlow,推荐给初学者:

    conda create -n tf tensorflow
    conda activate tf
    

    或者,要在 Linux 或 Windows 上安装当前版本的 GPU TensorFlow:

    conda create -n tf-gpu tensorflow-gpu
    conda activate tf-gpu
    

TensorFlow 现已安装并可以使用。

要在 GPU 上使用 TensorFlow,请参阅 有关该主题的 TensorFlow 文档,特别是有关设备放置的部分 。

CUDA 版本

GPU TensorFlow 使用 CUDA。在 Windows 和 Linux 上,TensorFlow 2.0 版本仅支持 CUDA 10.0。以前版本的 TensorFlow 支持其他版本的 CUDA。

要使用非默认 CUDA 版本(例如 9.0)安装 GPU TensorFlow,请运行:

conda create -n tf-gpu-cuda8 tensorflow-gpu cudatoolkit=9.0
conda activate tf-gpu-cuda8

蟒蛇 2

我们推荐 Python 3,但可以在 Linux 和 macOS 上将 TensorFlow 与 Python 2 结合使用。

Linux 或 macOS 上 Python 2 上的 CPU-only TensorFlow:

conda create -n tf-2 tensorflow python=2
conda activate tf-2

Linux 上 Python 2 上的 GPU TensorFlow:

conda create -n tf-2-gpu tensorflow python=2
conda activate tf-2-gpu

每晚构建

高级用户可能希望安装 TensorFlow 的最新夜间版本。这些夜间构建是不稳定的,只能作为 PyPI 上的 pip 包使用。

要安装仅使用 CPU 的 TensorFlow 每晚构建:

conda create -n tf-n python
conda activate tf-n
pip install tf-nightly

或者,要在 Linux 或 Windows 上安装夜间构建的 GPU TensorFlow:

conda create -n tf-n-gpu python
conda activate tf-n-gpu
pip install tf-nightly-gpu

在 Linux 或 macOS 上的 Python 2 上每晚构建仅 CPU 的 TensorFlow:

conda create -n tf-2-n python=2
conda activate tf-2-n
pip install tf-nightly

在 Linux 上的 Python 2 上每晚构建 GPU TensorFlow:

conda create -n tf-2-n-gpu python=2
conda activate tf-2-n-gpu
pip install tf-nightly-gpu