在CentOS上安装PyTorch的步骤如下:
方法一:使用pip安装
-
更新系统包
sudo yum update -y
-
安装依赖包
sudo yum install -y python3 python3-pip python3-devel
-
安装PyTorch 根据你的CUDA版本选择合适的PyTorch安装命令。以下是一些常见的CUDA版本对应的安装命令:
-
无GPU(CPU版本)
pip3 install torch torchvision torchaudio
-
CUDA 11.3
pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu113
-
CUDA 11.2
pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu112
-
CUDA 11.1
pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu111
-
CUDA 10.2
pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu102
-
CUDA 10.1
pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu101
-
CUDA 9.2
pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu92
-
CUDA 9.1
pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu91
-
CUDA 8.0
pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu80
请根据你的CUDA版本选择合适的命令。
-
-
验证安装
python3 -c "import torch; print(torch.__version__)"
方法二:使用conda安装
如果你已经安装了Anaconda或Miniconda,可以使用conda来安装PyTorch:
-
创建并激活conda环境
conda create -n pytorch_env python=3.8 conda activate pytorch_env
-
安装PyTorch 根据你的CUDA版本选择合适的安装命令:
-
无GPU(CPU版本)
conda install pytorch torchvision torchaudio cpuonly -c pytorch
-
CUDA 11.3
conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch
-
CUDA 11.2
conda install pytorch torchvision torchaudio cudatoolkit=11.2 -c pytorch
-
CUDA 11.1
conda install pytorch torchvision torchaudio cudatoolkit=11.1 -c pytorch
-
CUDA 10.2
conda install pytorch torchvision torchaudio cudatoolkit=10.2 -c pytorch
-
CUDA 10.1
conda install pytorch torchvision torchaudio cudatoolkit=10.1 -c pytorch
-
CUDA 9.2
conda install pytorch torchvision torchaudio cudatoolkit=9.2 -c pytorch
-
CUDA 9.1
conda install pytorch torchvision torchaudio cudatoolkit=9.1 -c pytorch
-
CUDA 8.0
conda install pytorch torchvision torchaudio cudatoolkit=8.0 -c pytorch
-
-
验证安装
python -c "import torch; print(torch.__version__)"
通过以上步骤,你应该能够在CentOS上成功安装PyTorch。如果有任何问题,请参考PyTorch官方文档或社区支持。