1. 环境准备 🛠️
- 操作系统:支持 Linux/macOS/Windows
- Python 版本:推荐 3.7-3.10(查看兼容性列表)
- GPU 配置(可选):需 NVIDIA 显卡 + CUDA 驱动(了解 GPU 支持详情)
2. 安装方法 🚀
方法一:pip 安装 📦
pip install tensorflow
⚠️ 若需指定版本:pip install tensorflow==2.12.0
方法二:从源码编译 🧬
git clone https://github.com/tensorflow/tensorflow.git
cd tensorflow
./configure
bazel build --config=opt --config=cuda //tensorflow:libtensorflow.so
方法三:Docker 容器 🐳
docker pull tensorflow/tensorflow:latest
docker run -it tensorflow/tensorflow:latest
3. 验证安装 🧪
运行以下代码检查是否成功:
import tensorflow as tf
print(tf.__version__)
✅ 若输出版本号则安装成功!