安装前准备 📦

在开始安装前,请确保已满足以下条件:

  • 已安装 Python(建议 3.7-3.10 版本)
  • 系统已配置 虚拟环境(推荐使用 venvconda
  • 网络连接正常(部分镜像源需科学上网)

安装方法 📦

方法一:使用 pip 安装

pip install tensorflow

✅ 安装完成后可验证版本:

import tensorflow as tf
print(tf.__version__)
TensorFlow_安装

方法二:使用 Docker 容器

docker run -it --rm tensorflow/tensorflow:latest

📌 容器启动后可通过 python 命令行测试 TensorFlow 功能

方法三:从源码编译(高级用户)

git clone https://github.com/tensorflow/tensorflow.git
cd tensorflow
./configure
bazel build --config=opt --config=cuda //tensorflow:libtensorflow.so

⚠️ 需要提前安装 Bazel 构建工具及 CUDA 环境

验证安装 🧪

运行以下代码验证 TensorFlow 是否正常工作:

import tensorflow as tf
hello = tf.constant("Hello, TensorFlow!")
print(session.run(hello))

🎉 若成功输出 Hello, TensorFlow! 表示安装完成

常见问题 ❓

TensorFlow_环境配置

建议安装后继续阅读 TensorFlow 快速入门教程 了解基础用法 📚