腾讯云国际站:腾讯云服务器怎样安装TensorFlow?

使用 pip 安装

  • 升级 pip :使用pip install --upgrade pip命令升级至最新版本的 pip。
  • 安装 TensorFlow :对于 CPU 版本,直接使用pip install tensorflow;对于 GPU 版本,使用pip install tensorflow-gpu
  • 验证安装 :在 Python 环境中输入import tensorflow as tf,若无报错,则说明安装成功。

使用 conda 安装

  • 创建虚拟环境 :使用 conda 创建新虚拟环境,如创建 Python 3.9 版本的环境可执行conda create --name tf python=3.9
  • 激活虚拟环境 :使用conda activate tf激活刚才创建的虚拟环境。
  • 安装 TensorFlow :在激活的虚拟环境中,使用conda install tensorflow安装 TensorFlow。

使用 Docker 安装

  • 安装 Docker :提前在腾讯云服务器上安装好 Docker。
  • 下载 TensorFlow Docker 镜像 :从 TensorFlow 官方 Docker 镜像仓库下载镜像,如下载最新稳定版的 CPU 二进制镜像可执行docker pull tensorflow/tensorflow
  • 启动 TensorFlow Docker 容器 :使用docker run [-it] [--rm] [-p hostPort:containerPort] tensorflow/tensorflow[:tag] [command]命令格式启动容器。