在 CentOS 上“装不上 PyTorch”通常并不是 PyTorch 不支持 CentOS,而是环境或依赖问题比较多。下面我按最常见原因 → 对应解决办法给你梳理一下。
PyTorch 新版本要求:
✅ 解决:
python3 --version
如果 < 3.8,建议用:
condapyenvCentOS 自带 pip 经常是旧版,或装到了系统 Python。
✅ 推荐做法(强烈):
conda create -n torch python=3.10
conda activate torch
比如你执行了:
pip install torch torchvision torchaudio
默认现在会尝试拉 CUDA 版本
✅ CPU 版显式安装:
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
PyTorch 新版本要求:
CentOS 7 是 2.17,很多新版直接装不上
✅ 解决:
pip install torch==1.13.1+cpu -f https://download.pytorch.org/whl/torch_stable.html
如果你试过:
pip install torch --no-binary
会需要:
✅ 安装:
yum install -y gcc gcc-c++ make cmake
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh
conda create -n torch python=3.10
conda activate torch
conda install pytorch torchvision torchaudio cpuonly -c pytorch
pip install torch==1.13.1+cpu torchvision==0.14.1+cpu -f https://download.pytorch.org/whl/torch_stable.html
我可以直接给你一条能跑的命令。