pytorch cuda安装报错的解决方法

 更新时间:2023年01月07日 10:27:53   作者:舒克儿不开飞机  
这篇文章主要给大家介绍了关于pytorch cuda安装报错的解决方法,文中通过图文介绍的非常详细,对大家学习或者使用Pytorch具有一定的参考学习价值,需要的朋友可以参考下

2022.12.8在win+cuda11.8下安装最新Pytorch GPU版时遇到包不兼容的问题,该文记录安装的整个流程

一、按照cuda版本在官网找命令

Pytorch官网命令如下

在win、cuda11.8下安装GPU版Pytorch

conda install pytorch torchvision torchaudio pytorch-cuda=11.7 -c pytorch -c nvidia

分析该命令,-c后面为安装包的源,-c pytorch表示使用官方源,可能出现速度慢等问题

二、换源

因此一般先将conda切换清华源

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/win-64/

三、Bug描述

换源后去掉-c执行命令如下

conda install pytorch torchvision torchaudio pytorch-cuda=11.7

报错包不兼容,出现冲突

Found conflicts! Looking for incompatible packages.
This can take several minutes.  Press CTRL-C to abort.
Examining torchaudio:  43%|██████████████████████████████████████████████▎                                                             | 3/7 [00:22<00:24,  6.10s/it]/failed                                                                                                                                                                

UnsatisfiableError: The following specifications were found
to be incompatible with the existing python installation in your environment:

Specifications:

  - torchaudio -> python[version='2.7.*|3.5.*|3.6.*|>=2.7,<2.8.0a0|>=3.5,<3.6.0a0|3.4.*']

Your python: python=3.7

If python is on the left-most side of the chain, that's the version you've asked for.
When python appears to the right, that indicates that the thing on the left is somehow
not available for the python version you are constrained to. Note that conda will not
change your python version to a different minor version unless you explicitly specify
that.

The following specifications were found to be incompatible with each other:

Output in format: Requested package -> Available versions

Package typing conflicts for:
torchvision -> typing_extensions -> typing[version='>=3.7.4']
pytorch -> typing_extensions -> typing[version='>=3.7.4']

Package pytorch conflicts for:
torchaudio -> pytorch[version='1.10.0|1.10.1|1.10.2|1.11.0|1.12.0|1.12.1|1.13.0|1.9.1|1.9.0|1.8.1|1.8.0|1.7.1|1.7.0|1.6.0']
torchvision -> pytorch[version='1.10.0|1.10.1|1.10.2|1.11.0|1.12.0|1.12.1|1.13.0|1.9.1|1.9.0|1.8.1|1.8.0|1.7.1|1.7.0|1.6.0|1.5.1|1.5.0|1.4.0|1.3.1|1.3.0|1.2.0|>=1.1.0|>=1.0.0|>=0.4']

Package pytorch-cuda conflicts for:
pytorch -> pytorch-cuda[version='>=11.6,<11.7|>=11.7,<11.8']
torchaudio -> pytorch-cuda[version='11.6.*|11.7.*']
torchvision -> pytorch==1.13.0 -> pytorch-cuda[version='>=11.6,<11.7|>=11.7,<11.8']
torchaudio -> pytorch==1.13.0 -> pytorch-cuda[version='>=11.6,<11.7|>=11.7,<11.8']
torchvision -> pytorch-cuda[version='11.6.*|11.7.*']

Package requests conflicts for:
python=3.7 -> pip -> requests
torchvision -> request

四、解决方法

参考之前安装成功的命令为

conda install pytorch torchvision torchaudio cudatoolkit=11.3

尝试执行

conda install pytorch torchvision torchaudio cudatoolkit=11.7

报错找不到包

PackagesNotFoundError: The following packages are not available from current channels:
  - cudatoolkit=11.7

推测原因可能是cuda11.7将cudatoolkit=11.7换为pytorch-cuda=11.7,而-c nvidia为pytorch-cuda的源。

执行如下命令成功安装

 conda install pytorch torchvision torchaudio pytorch-cuda=11.7 -c nvidia  

五、查看是否使用GPU

import torch

use_gpu = torch.cuda.is_available()
print(use_gpu)
print("devices count:", torch.cuda.device_count())

输出

True
devices count: 1

总结

到此这篇关于pytorch cuda安装报错解决的文章就介绍到这了,更多相关pytorch cuda安装报错内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • Anaconda安装pytorch和paddle的方法步骤

    Anaconda安装pytorch和paddle的方法步骤

    本文主要介绍了Anaconda安装pytorch和paddle的方法步骤,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2022-04-04
  • pandas 实现将NaN转换为None

    pandas 实现将NaN转换为None

    这篇文章主要介绍了pandas 实现将NaN转换为None的操作,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2021-05-05
  • 浅谈Python爬取网页的编码处理

    浅谈Python爬取网页的编码处理

    下面小编就为大家带来一篇浅谈Python爬取网页的编码处理。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2016-11-11
  • 简单的通用表达式求10乘阶示例

    简单的通用表达式求10乘阶示例

    这篇文章主要介绍了简单的通用表达式求10乘阶示例,需要的朋友可以参考下
    2014-03-03
  • Python pyecharts案例超市4年数据可视化分析

    Python pyecharts案例超市4年数据可视化分析

    这篇文章主要介绍了Python pyecharts案例超市4年数据可视化分析,文章围绕主题展开详细的内容介绍,具有一定的参考价值,需要的小伙伴可以参考一下
    2022-08-08
  • Python读取TIF影像的多种方法

    Python读取TIF影像的多种方法

    Python提供了丰富的库来读取和处理TIFF文件,其中PIL库是最常用的,本文给大家介绍Python读取TIF影像的几种方法,需要的朋友可以参考下
    2023-07-07
  • python实现自动抢课脚本的示例代码

    python实现自动抢课脚本的示例代码

    本文主要介绍了python实现自动抢课脚本的示例代码,文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2021-12-12
  • python实现文件分片上传的接口自动化

    python实现文件分片上传的接口自动化

    这篇文章主要为大家详细介绍了python实现文件分片上传的接口自动化,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2020-11-11
  • python通过apply使用元祖和列表调用函数实例

    python通过apply使用元祖和列表调用函数实例

    这篇文章主要介绍了python通过apply使用元祖和列表调用函数,实例分析了python中apply方法的使用技巧,需要的朋友可以参考下
    2015-05-05
  • Python单元测试框架unittest简明使用实例

    Python单元测试框架unittest简明使用实例

    这篇文章主要介绍了Python单元测试框架unittest简明使用实例,本文讲解了基本测试步骤、和测试实例,需要的朋友可以参考下
    2015-04-04

最新评论