在CentOS系统下安装PyTorch可以通过多种方式实现,包括使用Anaconda发行版或直接使用pip。以下是具体的安装步骤和注意事项:
安装Anaconda:
创建虚拟环境:
conda create -n pytorch python=3.8 conda activate pytorch 安装PyTorch:
conda install pytorch torchvision torchaudio cudatoolkit=11.8 -c pytorch 验证安装:
import torch print(torch.__version__) print(torch.cuda.is_available()) 安装pip(如果尚未安装):
sudo yum install python3-pip 安装PyTorch:
pip install torch torchvision torchaudio -f https://pypi.tuna.tsinghua.edu.cn/simple 验证安装:
import torch print(torch.__version__) print(torch.cuda.is_available()) 请注意,如果你需要使用GPU版本的PyTorch,确保你的系统上已经安装了兼容的NVIDIA GPU驱动和CUDA Toolkit。