栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

import torch中DLL load failed while importing

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

import torch中DLL load failed while importing

网上找了好多方法,大部分是换conda 环境,版本,激活,光激活试了好久,最终还是没有激活。(2)更换numpy的版本,python版本,方法都不行 。

最后找到一个方法,可能说是导入包模块时候路径的问题。

解决办法,将“D:anaconda3envsxxxxLibrarybin”添加到环境变量中。(把对应环境下的Librarybin添加到环境变量中)

 环境变量设置好了,重新执行一遍就ok了。

 

另外建议先试一下conda uninstall / pip uninstall numpy

也有可能是重复安装了numpy包导致的,或者在版本不是很敏感的情况下没准更新一次就解决了问题。(尽量不要混用pip和conda)

参考:

 Troubleshooting ImportError — NumPy v1.23.dev0 Manual

Eclipse and PyDev — Anaconda documentation

Using Python Environments in Visual Studio Code

Configure a Conda virtual environment | PyCharm

Managing environments — conda dev documentation

解决:

解决numpy:DLL load failed while importing _multiarray_umath: 找不到指定的模块。 - 猫猫子 - 博客园

2、第二个问题,jupyter中输入import torch,报错NameError: name ‘_C‘ is not defined,

这个问题也卡了很久,网上有安装VC++,也是版本不对齐什么,最后发现一步就解决。也不知道是不是碰上了,还是什么问题,目前反正是解决问题了。

NameError                                 Traceback (most recent call last)
Input In [3], in ()
----> 1 import torch

File D:Userslilinminiconda3libsite-packagestorch__init__.py:231, in 
    216         raise ImportError(textwrap.dedent('''
    217             Failed to load PyTorch C extensions:
    218                 It appears that PyTorch has loaded the `torch/_C` folder
   (...)
    226                 or by running Python from a different directory.
    227             ''').strip()) from None
    228     raise  # If __file__ is not None the cause is unknown, so just re-raise.
--> 231 __all__ += [name for name in dir(_C)
    232             if name[0] != '_' and
    233             not name.endswith('Base')]
    235 if not TYPE_CHECKING:
    236     # issue 38137 and python issue 43367. Submodules of a C extension are
    237     # non-standard, and attributes of those submodules cannot be pickled since
    238     # pickle expect to be able to import them as "from _C.sub import attr"
    239     # which fails with "_C is not a package
    240     for attr in dir(_C):

NameError: name '_C' is not defined

解决办法:cmd输入

pip install Cython

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/886620.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号