TensorFlow#

TensorFlow 支持您的数据科学、机器学习和人工智能工作流程。 本页介绍如何使用 Anaconda 和 Miniconda 中包含的 conda 包管理器安装 TensorFlow。

在 64 位 Ubuntu Linux 16.04 或更高版本以及 macOS 10.12.6 或更高版本上支持使用 conda 的 TensorFlow CPU。

通过 conda 提供的 TensorFlow GPU 仅适用于 2.4.1 版本(2021 年)。 对于最新的 TensorFlow GPU 安装,请按照 TensorFlow 网站上的安装说明 进行操作。

安装 TensorFlow#

  1. 下载并安装 AnacondaMiniconda

  2. 打开终端应用程序并使用默认的 bash shell。

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

  4. 使用以下命令安装当前版本的 TensorFlow。 建议初学者使用仅 CPU 版本。

    conda create --name tf tensorflow
    conda activate tf
    

    注意

    GPU TensorFlow 仅通过 conda 在 Windows 和 Linux 上可用。

    conda create --name tf-gpu tensorflow-gpu
    conda activate tf-gpu
    

TensorFlow 现已安装完成,可以使用了。

要将 TensorFlow 与 GPU 结合使用,请参阅 TensorFlow 文档,特别是关于 设备放置 的部分。

CUDA 版本#

GPU TensorFlow 使用 CUDA。 有关 Linux 上 GPU TensorFlow 的版本兼容性表,请参阅 https://tensorflowcn.cn/install/source#gpu。 对于 Windows,请参阅 https://tensorflowcn.cn/install/source_windows#gpu

GPU TensorFlow conda 包目前仅支持 Windows 或 Linux。

注意

TensorFlow 2.10 是最后一个在 Windows Native 上支持 GPU 的版本。

要使用非默认 CUDA 版本(如 9.0)安装 GPU TensorFlow,请运行以下命令

conda create --name tf-gpu-cuda9 tensorflow-gpu cudatoolkit=9.0
conda activate tf-gpu-cuda9

Nightly builds#

高级用户可能希望安装 TensorFlow 的最新 nightly build。 这些 nightly build 不稳定,仅作为 PyPI 上的 pip 包提供。

要安装仅 CPU TensorFlow 的 nightly build

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

或者,要在 Linux 或 Windows 上安装 GPU TensorFlow 的 nightly build

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