使用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

相关推荐
糖果店的幽灵2 分钟前
大模型测评DeepEval快速入门-安全与通用指标详解
人工智能·安全·langgraph·大模型测评·deepeval
江畔柳前堤6 小时前
roLabelImg 详细安装教程
开发语言·人工智能·后端·云原生
阿里云大数据AI技术6 小时前
分链路差异化设计的DSP准实时数仓|钛动科技基于阿里云实时计算 Flink 版 + DLF Paimon + EMR Serverless StarRocks 的实践
人工智能·flink
陕西企来客6 小时前
2026年7月AI智能搜索曝光趋势研判
大数据·人工智能·机器学习·ai智能搜索曝光
0566466 小时前
agent学习Day15——SQLAlchemy 查询过滤、分页与历史列表接口
python·学习·fastapi
阿里云大数据AI技术7 小时前
从算力到智能体,面向 Agentic AI 的基础设施演进
人工智能·agent
程序员爱德华7 小时前
Python与C++:异同点对比
c++·python
hangyuekejiGEO7 小时前
GEO技术服务选型指南
大数据·人工智能·python
阿里云大数据AI技术8 小时前
EMR Serverless Spark AI Function 的双维降本实践
人工智能·sql·spark
软萌萌的18 小时前
Java Spring Boot 修改yml配置&加载顺序规则
java·spring boot·python