本文将为您详细介绍如何在您的计算机上安装TensorFlow。TensorFlow是一个由Google开发的开源机器学习框架,广泛用于各种机器学习和深度学习任务。

安装步骤

  1. 系统要求

    • 操作系统:Windows、macOS、Linux
    • Python版本:Python 3.5 或更高版本
  2. 安装TensorFlow

    使用pip(Python包管理器)进行安装:

    pip install tensorflow
    

    如果您需要安装TensorFlow GPU版本,请使用以下命令:

    pip install tensorflow-gpu
    
  3. 验证安装

    安装完成后,您可以通过运行以下代码来验证TensorFlow是否已正确安装:

    import tensorflow as tf
    print(tf.__version__)
    

    如果输出TensorFlow的版本号,则表示安装成功。

示例

以下是一个简单的TensorFlow示例:

import tensorflow as tf

# 创建一个简单的计算
a = tf.constant(5)
b = tf.constant(6)
c = a + b

# 启动TensorFlow会话
with tf.Session() as sess:
    # 运行计算
    print(sess.run(c))

输出结果为:

11

更多资源

如果您想了解更多关于TensorFlow的信息,请访问我们的官方文档

相关链接

希望这个指南能帮助您顺利安装TensorFlow!🎉

TensorFlow Installation