import torch中DLL load failed while importing _multiarray_umath: 找不到指定的模块,一步解决。

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

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

解决办法,将“D:\anaconda3\envs\xxxx\Library\bin”添加到环境变量中。(把对应环境下的Library\bin添加到环境变量中)

 环境变量设置好了,重新执行一遍就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 <cell line: 1>()
----> 1 import torch

File D:\Users\lilin\miniconda3\lib\site-packages\torch\__init__.py:231, in <module>
    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

 

来源:lleen-Lee

物联沃分享整理
物联沃-IOTWORD物联网 » import torch中DLL load failed while importing _multiarray_umath: 找不到指定的模块,一步解决。

发表评论