Windows 11 下使Python3.12 支持 Pytorch GPU版

Title Windows 11 下使Python3.12 支持 Pytorch GPU版
Framework Windows 11
User wy8817399@vip.qq.com
Id 62
Created 2/27/26, 10:02 PM
Modified 3/2/26, 3:08 PM
Published Yes
Content

1、下载并安装Visual Studio

https://visualstudio.microsoft.com/


2、下载CUDA并安装

https://developer.nvidia.com/cuda-downloads

 

3、给Python创建一个虚拟环境

python -m venv PyTorchEnv
cd PyTorchEnv\Scripts

# 如果是Powershell
#如果遇到安全问题,输入以下命令按Y
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
#然后再执行下面语句 进入虚拟环境
.\Activate.ps1

# 如果是cmd,直接执行activate即可
activate



4、在虚拟环境下,下载安装Pytorch,这样可以避免和主Python依赖冲突

https://pytorch.org/
# 自己在网页上挑选自己适合的版本
pip3 install torch torchvision --index-url https://download.pytorch.org/whl/cu130

 

5、查看是否安装成功

pip list
torch             2.10.0+cu130
torchvision       0.25.0+cu130


6、设置pip镜像

pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
pip config set install.trusted-host mirrors.aliyun.com

 

7、退出虚拟环境

deactivate