操作系统:Win11

PyTorch

https://pytorch.org/
https://pytorch.org/get-started/locally/

历史版本
Installing previous versions of PyTorch
https://pytorch.org/get-started/previous-versions/

一、PyTorch 2.5.1 GPU版安装

1.1 conda使用清华镜像加速

C:\Users\user\.condarc
channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
show_channel_urls: true

1.2 安装

# pytorch251cu124 python=3.12.7

conda create --name pytorch251gpu python=3.12.7
conda activate pytorch251gpu
conda install pytorch==2.5.1 torchvision==0.20.1 torchaudio==2.5.1 pytorch-cuda=12.4 -c pytorch -c nvidia

1.3 360杀毒报病毒


D:\programs\anaconda3\pkgs\libjpeg-turbo-2.0.0-h196d8e1_0\library\bin\wrjpgcom.exe

安装失败:

Preparing transaction: done
Verifying transaction: failed

CondaVerificationError: The package for libjpeg-turbo located at D:\Programs\anaconda3\pkgs\libjpeg-turbo-2.0.0-h196d8e1_0
appears to be corrupted. The path 'Library/bin/wrjpgcom.exe'
specified in the package manifest cannot be found.

1.4 换coda的镜像加速

开始以为是清华镜像的问题,后发感觉好像不是。

C:\Users\user\.condarc
channels:
  - https://repo.anaconda.com/pkgs/main/
show_channel_urls: true

1.5 重新安装

conda deactivate
conda remove -n pytorch251gpu --all 
conda create --name pytorch251gpu python=3.12.7
conda activate pytorch251gpu
conda install pytorch==2.5.1 torchvision==0.20.1 torchaudio==2.5.1 pytorch-cuda=12.4 -c pytorch -c nvidia

又报错:清华镜像加速和conda镜像加速报错相同。

Downloading and Extracting Packages:
InvalidArchiveError("Error with archive D:\\Programs\\anaconda3\\pkgs\\libjpeg-turbo-2.0.0-h196d8e1_0.conda.  You probably need to delete and re-download or re-create this file.  Message was:\n\nfailed with e)

1.6 清理 Conda 缓存

conda clean --all --yes

再安装还是报错,

1.7 临时关闭杀毒软件防护

再安装就好了。

可以考虑把wrjpgcom.exe加上后缀.bak

二、PyTorch 2.5.1 CPU版安装

# pytorch251 cpu python=3.12.7
conda create --name pytorch251cpu python=3.12.7
conda activate pytorch251cpu
conda install pytorch==2.5.1 torchvision==0.20.1 torchaudio==2.5.1 cpuonly -c pytorch

如果报错,可考虑

清理 Conda 缓存
conda clean --all --yes

后来安装命令换成这个就好了

pip install torch==2.5.1 torchvision==0.20.1 torchaudio==2.5.1 --index-url https://download.pytorch.org/whl/cpu

cpu版安装,不用关闭杀毒软件防护

更多推荐