TensorFlow 安装指南

TensorFlow 是一个开源的机器学习框架,由 Google 开发。以下是如何在您的系统上安装 TensorFlow 的步骤。

系统要求

在安装 TensorFlow 之前,请确保您的系统满足以下要求:

  • 操作系统:Linux、macOS 或 Windows
  • Python 版本:Python 3.6 或更高版本

安装步骤

  1. 安装 Python

    确保您已经安装了 Python 3.6 或更高版本。您可以通过访问 Python 官网 来下载并安装 Python。

  2. 创建虚拟环境(可选

    创建一个虚拟环境可以避免 TensorFlow 与其他 Python 包的冲突。使用以下命令创建虚拟环境:

    python3 -m venv tf_venv
    

    然后激活虚拟环境:

    • Linux/macOS:

      source tf_venv/bin/activate
      
    • Windows:

      .\tf_venv\Scripts\activate
      
  3. 安装 TensorFlow

    在虚拟环境中,使用以下命令安装 TensorFlow:

    pip install tensorflow
    

    或者,如果您需要 GPU 支持的版本:

    pip install tensorflow-gpu
    
  4. 验证安装

    安装完成后,您可以运行以下 Python 代码来验证 TensorFlow 是否已成功安装:

    import tensorflow as tf
    print(tf.__version__)
    

    如果一切正常,您将看到 TensorFlow 的版本号。

其他资源

如果您需要更多帮助或有其他问题,请访问 TensorFlow 官方文档

TensorFlow Logo