以下是在Ubuntu上安装PyTorch的详细步骤:
sudo apt update。sudo apt install python3 python3-pip python3-venv -y。pip3 install torch==2.6.0 torchvision==0.17.0 torchaudio==2.6.0 --index-url https://download.pytorch.org/whl/cpu。pip3 install torch==2.6.0 torchvision==0.17.0 torchaudio==2.6.0 --index-url https://download.pytorch.org/whl/cu126(以CUDA 12.6为例)。bash Anaconda3-2023.07-Linux-x86_64.sh,安装后激活环境source ~/.bashrc。conda create -n pytorch_env python=3.8,激活环境conda activate pytorch_env。conda install pytorch torchvision torchaudio cpuonly -c pytorch;GPU版本用conda install pytorch torchvision torchaudio cudatoolkit=<cuda_version> -c pytorch(将<cuda_version>替换为实际版本)。在Python解释器中运行:
import torch
print(torch.__version__)
print(torch.cuda.is_available())