1. 安装方式概览 📦
TensorFlow Keras 可通过以下方式安装,选择适合你开发环境的方案:
推荐方式:使用 pip 安装 🚀
pip install tensorflow
pip 安装会自动包含 Keras 和 TensorFlow 的最新版本,适合大多数用户。
Conda 环境安装 🐍
conda install -c conda-forge tensorflow
如果使用 Anaconda,Conda 安装可简化依赖管理。
从源代码编译安装 💻
- 克隆 TensorFlow 仓库:
git clone https://github.com/tensorflow/tensorflow.git
- 进入目录并编译:
cd tensorflow ./configure bazel build --config=opt //tensorflow:tensorflow
适用于需要自定义配置的高级用户。
- 克隆 TensorFlow 仓库:
2. 验证安装 ✅
安装完成后,运行以下代码验证是否成功:
import tensorflow as tf
print(tf.__version__)
如果输出版本号(如
2.12.0
),说明安装正常。
3. 扩展阅读 📖
如需了解 Keras 的使用方法,可访问 TensorFlow Keras 教程。
或查看 TensorFlow 官方文档 获取更多细节。