python错误:ImportError: DLL load failed while importing _multiarray_umath

转载自:解决numpy:DLL load failed while importing _multiarray_umath: 找不到指定的模块。 - 猫猫子 - 博客园 (cnblogs.com)

1 问题描述

使用conda install numpy 装包。安装过程中一切正常,但是最后使用的时候却不止一次的报错:

先说一下我的环境:windows系统下使用 numpy1.20 + conda管理包环境 + python版本1.19

>>> import numpy
D:\python\envs\raft\lib\site-packages\numpy\__init__.py:138: UserWarning: mkl-service package failed to import, therefore Intel(R) MKL initialization ensuring its correct out-of-the box operation under condition when Gnu OpenMP had already been loaded by Python process is not assured. Please install mkl-service package, see http://github.com/IntelPython/mkl-service
  from . import _distributor_init
Traceback (most recent call last):
  File "D:\python\envs\raft\lib\site-packages\numpy\core\__init__.py", line 22, in <module>
    from . import multiarray
  File "D:\python\envs\raft\lib\site-packages\numpy\core\multiarray.py", line 12, in <module>
    from . import overrides
  File "D:\python\envs\raft\lib\site-packages\numpy\core\overrides.py", line 7, in <module>
    from numpy.core._multiarray_umath import (
ImportError: DLL load failed while importing _multiarray_umath: 找不到指定的模块。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\python\envs\raft\lib\site-packages\numpy\__init__.py", line 140, in <module>
    from . import core
  File "D:\python\envs\raft\lib\site-packages\numpy\core\__init__.py", line 48, in <module>
    raise ImportError(msg)
ImportError:

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.

We have compiled some common reasons and troubleshooting tips at:

    https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  * The Python version is: Python3.8 from "D:\python\envs\raft\python.exe"
  * The NumPy version is: "1.19.2"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: DLL load failed while importing _multiarray_umath: 找不到指定的模块。

这真的是一个困扰了我很久的问题。网上查了很多办法,无非都是重新安装或者换个版本之类治标不治本的方法。当我正在使用某一个特定版本的conda 环境,我不愿意随意的更改numpy的版本(有很多包依赖于底层的numpy版本,且这个问题我在其它的python和numpy版本中也遇到了,显然不是换个版本就可以解决的)。同时重装也是个没什么用的方法。我重装了一边conda,问题还是依旧。所以把我的方法贴在下面:

2 解决

这个问题应该是一个导入包模块时候路径的问题。读者应该把“D:\anaconda3\envs\xxxx\Library\bin”添加到环境变量中。

这里情况可能因人而异,需要把xxxx改成自己的conda环境。但是核心就是把对应环境下的Library\bin添加到环境变量中。

miniconda3的路径不一样,在:C:\Users\xxx\miniconda3\Library\bin

当然还是建议读者先试一下conda uninstall / pip uninstall numpy 因为也有可能是重复安装了numpy包导致的,或者在版本不是很敏感的情况下没准更新一次就解决了问题。

(顺便一提:尽量不要混用pip和conda)

3 关于dll

dll(全称dynamic link libraries,动态链接库)文件,是windows下一个用于连接函数功能供其它应用程序调用与引入的文件。由于是windows 早期架构的一部分,dll文件已经成为了很多代码构建的重要部分。有兴趣的同学可以去了解一下dll hell,这里就不展开啦

posted @ 2021-11-29 21:44  zhengcixi  阅读(4568)  评论(0编辑  收藏  举报
回到顶部