当前位置: 首页> 汽车> 新车 > 使用requirements.txt文件安装cuda(GPU)版本的pytorch

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

时间:2025/7/11 7:36:06来源:https://blog.csdn.net/EstrangedZ/article/details/140416216 浏览次数: 0次

使用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
在这里插入图片描述
在这里插入图片描述

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

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: