windows 11 安装 pytorch 2.6 以上版本

在 pytorch2.6 之后,pytorch 取消了 conda 的安装支持,理由是依赖关系复杂,而 conda 管理架构不足以支持这种复杂性。

现在只有 pip 的安装方法,但问题是用 pip 直接安装速度过慢,经过查找,阿里源同步了 pytorch 的源目录。

  1. 卸载现有的 nvidia 驱动。
  2. 到 cuda toolkit 下载 12.6 版本的安装包,里面包含了nvidia驱动。
  3. 安装 visual studio 2022 的社区版,cuda有些组件需要用它编译。
  4. 安装python 3.12版本,注意将path加入系统目录。
  5. 创建 python 虚拟环境 torch
python -m venv torch
./torch/script/activate
  1. 安装下载好的cuda toolkit 包。
  2. 使用阿里云的 pip 源,命令如下:
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple
pip config set install.trusted-host mirrors.aliyun.com

配置会记录到 pip.ini 文件中
Writing to C:/Users/Logic/AppData/Roaming/pip/pip.ini

  1. 使用 pip 安装 朋友torch 2.6,命令如下
pip install torch==2.6.0 torchvision torchaudio  -f https://mirrors.aliyun.com/pytorch-wheels/cu126/
  1. 使用下述 python 代码测试 pytorch 安装是否成功
# 运行python,进入python环境
import torch
x = torch.rand(5, 3)
print(x)
print(torch.__version__)

总结

主要的问题就是找到同步 pytorch 的阿里云,然后,根据pip命令指定下载和安装 pytorch 的源是阿里云的地址。
另外,pytorch 2.7 主要是更新了对 nvidia 50系列显卡的支持,如果只有40系列的显卡,2.6就很好。
还有 pip 的配置目录,windows 11 的地址是:C:\Users\Home_name\AppData\Roaming\pip\pip.ini

posted @ 2025-04-25 13:57  立体风  阅读(396)  评论(0)    收藏  举报