numpy:DLL load failed while importing _multiarray_umath: 找不到指定的模塊。
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添加到環境變量中。)
當然還是建議讀者先試一下conda uninstall / pip uninstall numpy 因為也有可能是重復安裝了numpy包導致的,或者在版本不是很敏感的情況下沒准更新一次就解決了問題。
(順便一提:盡量不要混用pip和conda)
3關於dll
dll(全稱dynamic link libraries,動態鏈接庫)文件,是windows下一個用於連接函數功能供其它應用程序調用與引入的文件。由於是windows 早期架構的一部分,dll文件已經成為了很多代碼構建的重要部分。有興趣的同學可以去了解一下dll hell,這里就不展開啦
