原文阅读:【巨人肩膀社区·专栏·分享】服务器安装pytorch-阿里云-centos7
1、创建一个虚拟环境
conda create -n pytorch python=3.10
安装成功:

但是使用上面的命令会失败(疑问?),使用下面的这个可以:
source activate pytorch

如果版本太高会报这个错:
Collecting package metadata (current_repodata.json): done
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: failed
PackagesNotFoundError: The following packages are not available from current channels:
- python=3.12.5
Current channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/linux-64
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/noarch
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r/linux-64
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r/noarch
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2/linux-64
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2/noarch
To search for alternate channels that may provide the conda package you're
looking for, navigate to
https://anaconda.org
and use the search bar at the top of the page.
2、配置安装PyTorch命令

pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu -i https://mirrors.bfsu.edu.cn/pypi/web/simple --trusted-host mirrors.bfsu.edu.cn
其中-i https://mirrors.bfsu.edu.cn/pypi/web/simple --trusted-host mirrors.bfsu.edu.cn是临时切换pip3下载源,其他部分都是从PyTorch官网配置后复制的。
安装成功截图:

3、验证pip3 list

import torch
print(torch.__version__)

成功打印出了版本号就说明安装成功啦。