在CentOS上安装PyTorch有多种方法,以下是一些详细的教程:
安装Miniconda:
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh
创建并激活conda环境:
conda create -n pytorch_env python=3.8
conda activate pytorch_env
安装PyTorch:
conda install pytorch torchvision torchaudio cudatoolkit=11.7 -c pytorch
conda install pytorch torchvision torchaudio cpuonly -c pytorch
验证安装:
import torch
print(torch.__version__)
print(torch.cuda.is_available())
如果输出PyTorch的版本号且torch.cuda.is_available()
返回True,则表示安装成功并可以使用GPU。更新系统包:
sudo yum update -y
安装依赖项:
sudo yum install -y python3 python3-pip python3-devel
安装PyTorch:
pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu117
pip3 install torch torchvision torchaudio
验证安装:
import torch
print(torch.__version__)
print(torch.cuda.is_available())
如果一切正常,你应该能看到PyTorch的版本号以及CUDA是否可用。配置清华镜像源:
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
安装PyTorch:
pip install torch torchvision torchaudio
希望这些步骤能帮助你在CentOS上成功安装PyTorch。如果在安装过程中遇到问题,建议查阅PyTorch官方文档或寻求社区的帮助。