使用requirements.txt文件安装cuda(GPU)版本的pytorch

使用requirements.txt文件安装cuda(GPU)版本的pytorch

问题描述

使用requirements.txt可以轻松地帮助我们配置新环境,然而,当使用requirements.txt安装pytorch时有时会出现仅能安装cpu版本pytorch的情况。

举例说明:

requirements.txt文件内容如下:

复制代码
torch==2.0.1
torchaudio==2.0.2
torchvision==0.15.2

此时在anaconda promot中输入

复制代码
pip install -r requirements.txt

然后会发现,安装的是cpu版本的pytorch

这里输出的也是False

解决方法

应该将requirements.txt文件改为如下形式

复制代码
torch==2.0.1+cu117
torchaudio==2.0.2+cu117
torchvision==0.15.2+cu117
-f https://download.pytorch.org/whl/torch_stable.html

然后再在anaconda promot中输入

复制代码
pip install -r requirements.txt

此时安装的就是cuda版本的pytorch

这里输出是True

相关推荐
IT_陈寒1 小时前
JavaScript的闭包把我坑惨了,说好的内存会自动回收呢?
前端·人工智能·后端
星云穿梭3 小时前
用Python写一个带图形界面的学生管理系统——完整教程
python
金銀銅鐵3 小时前
用 Pygame 实现 15 puzzle
python·数学·游戏
jooloo5 小时前
Codex 间歇性 400 之谜:一条对话里,它为什么有时候用 chat/completions,有时候切到 responses?
人工智能
用户5191495848455 小时前
OpenSSL PKCS#12 PBMAC1 堆栈缓冲区溢出漏洞 (CVE-2025-11187) 分析与验证
人工智能·aigc
用户5191495848456 小时前
HP Sound Research SECOMNService 权限提升漏洞利用工具
人工智能·aigc
用户018349301696 小时前
给 AI 智能体能力包一层 BFF,前端只调一个接口
人工智能
黄忠9 小时前
大模型之LangGraph技术体系
python·llm
这token有力气10 小时前
Function Calling 格式漂移
人工智能
onething36510 小时前
Spring Boot + Spring AI 从入门到实战:7天转型计划 Day 5 —— SSE 流式输出 + 打字机效果
人工智能·后端·全栈