在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安裝PyTorch,可以按照以下步驟進行:
安裝pip(如果尚未安裝)
yum install python3-pip
安裝PyTorch
pip install torch torchvision torchaudio -f https://pypi.tuna.tsinghua.edu.cn/simple
請注意,如果你需要使用GPU版本的PyTorch,確保你的系統上已經安裝了兼容的NVIDIA GPU驅動和CUDA Toolkit。此外,不同版本的PyTorch可能對CUDA和cuDNN的版本有特定要求,請根據你的具體需求選擇合適的版本進行安裝。