报错“ImportError: Failed to load PyTorch C extensions:”

完整报错

ImportError: Failed to load PyTorch C extensions:
    It appears that PyTorch has loaded the `torch/_C` folder
    of the PyTorch repository rather than the C extensions which
    are expected in the `torch._C` namespace. This can occur when
    using the `install` workflow. e.g.
        $ python setup.py install && python -c "import torch"

    This error can generally be solved using the `develop` workflow
        $ python setup.py develop && python -c "import torch"  # This should succeed
    or by running Python from a different directory.

解决过程

出错可能性

在这里插入图片描述

自检pytorch有没有安装好

检测方法参考这篇大佬的文章(请自行检查自己的cuda版本,我的cuda版本是12.3)
检查下来发现一切正常
在这里插入图片描述

import torch
print("Is CUDA available:", torch.cuda.is_available())
print("CUDA version:", torch.version.cuda)

解决问题

发现用的解释器环境路径和自检时的python版本不一样,之前用的环境是“lunwen(2)”,python版本是3.10
在这里插入图片描述
而刚才自检的时候python版本是3.12
在这里插入图片描述
这个时候才意识到此时的python.exe路径错了
重新加载回正确的conda路径后,报错解决
在这里插入图片描述

问题总结

这次报错不是因为pytorch没安装好,也不是因为安装版本不对,而是使用的python.exe路径不对,导致import torch失败

  • 6
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Pycharm报错ImportError: DLL load failed: 找不到指定的模块,可能是由于缺少相应的依赖库或者库文件无法正确加载所致。您可以尝试以下几种解决方法: 1. 确保您安装了所需的依赖库。根据您提供的信息,看起来是与matplotlib和其他库相关的问题。请确保您已正确安装了这些库。您可以使用conda或pip来安装它们。您可以运行`conda list`或`pip list`来查看已安装的库。 2. 检查库文件是否存在。DLL load failed错误通常是由于缺少或无法加载库文件引起的。请确保库文件存在于正确的位置,并且可以被系统正确加载。您可以尝试重新安装库文件,或者将库文件路径添加到系统的环境变量中。 3. 检查是否存在冲突。有时候,不同版本的库文件可能会引起冲突,导致DLL load failed错误。您可以尝试卸载并重新安装相关库,确保它们的版本兼容。 4. 检查Pycharm的配置。在Pycharm中,您可以检查项目的解释器设置,确保使用的解释器是正确配置的,并且已安装了所需的库。 总之,解决ImportError: DLL load failed: 找不到指定的模块的问题通常需要检查依赖库的安装情况、库文件的存在性以及Pycharm的配置等方面。希望以上方法可以帮助您解决问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [Pycharm中出现ImportError:DLL load failed:找不到指定模块的解决方法](https://blog.csdn.net/qq_28714865/article/details/99111240)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值