tensorflow安装
时间: 2023-11-01 19:00:04 浏览: 13
以下是在 Windows 操作系统下安装 TensorFlow 的步骤:
1. 安装 Anaconda:在 Anaconda 官网(https://www.anaconda.com/products/individual)下载适合自己操作系统的版本,然后安装。
2. 创建虚拟环境:打开 Anaconda Prompt(或者在命令行中),输入以下命令创建一个名为 tensorflow 的虚拟环境:
```
conda create -n tensorflow python=3.8
```
3. 激活虚拟环境:输入以下命令激活刚刚创建的虚拟环境:
```
conda activate tensorflow
```
4. 安装 TensorFlow:输入以下命令安装最新版本的 TensorFlow:
```
pip install tensorflow
```
5. 测试 TensorFlow:输入以下代码进行测试:
```
import tensorflow as tf
tf.compat.v1.disable_eager_execution()
hello = tf.constant('Hello, TensorFlow!')
sess = tf.compat.v1.Session()
print(sess.run(hello))
```
如果输出了 "Hello, TensorFlow!",则说明 TensorFlow 安装成功。
注意:以上步骤仅在 Windows 操作系统下适用。在 Linux 或 macOS 环境下,可能需要进行不同的安装步骤。