在 CentOS 上下载/安装 PyTorch,通常有两种常用方式:pip 和 conda。下面按常见场景说明。
CentOS 7/8 一般自带 Python,但建议用新版本:
# CentOS 7
sudo yum install -y python3 python3-pip
# 检查
python3 --version
pip3 --version
pip3 install torch torchvision torchaudio
先确认 CUDA 版本:
nvidia-smi
例如 CUDA 11.8:
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh
source ~/.bashrc
conda create -n torch python=3.10
conda activate torch
CPU:
conda install pytorch torchvision torchaudio cpuonly -c pytorch
GPU(CUDA 11.8):
conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia
python3
import torch
print(torch.__version__)
print(torch.cuda.is_available())
pip3 install torch -i https://pypi.tuna.tsinghua.edu.cn/simple
如果你能告诉我:
我可以给你更精确的命令。