import numpy報錯:ImportError: DLL load failed: 找不到指定的模組。
阿新 • • 發佈:2019-01-13
我的numpy的版本是1.15.1,我使用的是anaconda環境。
今天在匯入numpy庫時遇到了一個出乎意料的錯誤
>>> import numpy
Traceback (most recent call last):
File "C:\Users\peter\AppData\Local\Continuum\anaconda3\lib\site-packages\numpy\core\__init__.py", line 16, in <module>
from . import multiarray
ImportError: DLL load failed: 找不到指定的模組。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\peter\AppData\Local\Continuum\anaconda3\lib\site-packages\numpy\__init__.py", line 142, in <module>
from . import add_newdocs
File "C:\Users\peter\AppData\Local\Continuum\anaconda3\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "C:\Users\peter\AppData\Local\Continuum\anaconda3\lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
from .type_check import *
File "C:\Users\peter\AppData\Local\Continuum\anaconda3\lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "C:\Users\peter\AppData\Local\Continuum\anaconda3\lib\site-packages\numpy\core\__init__.py", line 26, in <module>
raise ImportError(msg)
ImportError:
Importing the multiarray numpy extension module failed. Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try `git clean -xdf` (removes all
files not under version control). Otherwise reinstall numpy.
Original error was: DLL load failed: 找不到指定的模組。
令人驚奇的是我在sypder中import numpy不會報錯,而在命令列裡import numpy會報上圖的錯。
解決方法1
這個問題可能是libiomp5md.dll造成的。
如果你的C:\Windows\System32目錄下存在libiomp5md.dll這個dll,
而numpy自己也有一個libiomp5md.dl,在C:\Users\peter\AppData\Local\Continuum\anaconda3\Library\bin\libiomp5md.dll
那麼numpy很可能會不知道應該載入哪個dll。
解決方法就是把C:\Windows\System32目錄下的libiomp5md.dll重新命名為libiomp5md.dll.bak(如果其他程式要用到這個DLL,以後再說)
解決方法2
這個問題也有可能是intel的DLL檔案造成的。
intel有mkl*.dll在C:\Users\peter\AppData\Local\Continuum\anaconda3\Library\bin目錄下,
把這個目錄新增到PATH,系統的環境變數裡,然後重啟終端就可以了(注意替換成自己的目錄)。
解決方案3
如果上面的2個解決方案都不能奏效,那麼可以嘗試重灌numpy
pip uninstall numpy
pip install numpy
這個方法有奇效
參考資料:
- import numpy failed with Anaconda 4.0.0 in Windows 7 (maybe related to multiarray) · Issue #835 · ContinuumIO/anaconda-issues
- When trying to use numpy: “DLL Load Failed: The specified procedure could not be found.” · Issue #1508 · ContinuumIO/anaconda-issues
- python - ImportError: DLL load failed when importing Numpy installed in conda virtual environment