본문 바로가기

프로그래밍/Python

[Anaconda] ImportError: DLL load failed while importing _multiarray_umath: 지정된 모듈을 찾을 수 없습니다.

반응형

anaconda3 를 윈도우에 설치하고, import numpy, import pandas 를 입력했으나
ImportError: DLL load failed while importing _multiarray_umath: 지정된 모듈을 찾을 수 없습니다. 와 같은 에러가 발생했다.

전제 에러메시지는 다음과 같다.

C:\ProgramData\Anaconda3>python
Python 3.8.5 (default, Sep  3 2020, 21:29:08) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32

Warning:
This Python interpreter is in a conda environment, but the environment has
not been activated.  Libraries may fail to load.  To activate this environment
please see https://conda.io/activation

Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
C:\ProgramData\Anaconda3\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 "C:\ProgramData\Anaconda3\lib\site-packages\numpy\core\__init__.py", line 22, in <module>
    from . import multiarray
  File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\core\multiarray.py", line 12, in <module>
    from . import overrides
  File "C:\ProgramData\Anaconda3\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 "C:\ProgramData\Anaconda3\lib\site-packages\numpy\__init__.py", line 140, in <module>
    from . import core
  File "C:\ProgramData\Anaconda3\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 "C:\ProgramData\Anaconda3\python.exe"
  * The NumPy version is: "1.19.1"

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: 지정된 모듈을 찾을 수 없습니다.

이런 문제는 anaconda 파이썬을 anaconda prompt 에서 실행하지 않았기 때문에 발생한 것이다.
위 메시지 중 처음에 보면 다음과 같은 구문이 있다.

Warning:
This Python interpreter is in a conda environment, but the environment has
not been activated.  Libraries may fail to load.  To activate this environment
please see https://conda.io/activation

위 메시지를 번역해 보면 다음과 같다.

"경고: 이 파이썬 인터프리터는 콘다환경에 속한 것이다.
그런데 환경(콘다환경)이 활성화(activate)되지 않았다. 라이브러리 로딩이 실패할 수 있다.
이 환경을 활성화(activate)하는 방법은 https://conda.io/activation 를 참고하라.

아나콘다 환경을 도스창(명령창)에서 정확하게 이용하는 방법은 conda prompt 로 명령창을 열어서 이용하는 것이다. conda prompt 에는 실행에서 cmd 를 입력하여 실행한 기본 도스창(명령창)과는 달리 해당 아나콘다 환경을 이용하기 위한 몇가지 환경변수가 더 정의되어 있고, 그 환경변수들은 set 명령으로 확인해 볼 수 있다.

(base) C:\ProgramData\Anaconda3\Scripts>set
ALLUSERSPROFILE=C:\ProgramData
APPDATA=C:\Users\userme\AppData\Roaming
CommonProgramFiles=C:\Program Files\Common Files
CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files
CommonProgramW6432=C:\Program Files\Common Files
...
ComSpec=C:\windows\system32\cmd.exe
CONDA_DEFAULT_ENV=base
CONDA_EXE=C:\ProgramData\Anaconda3\Scripts\conda.exe
CONDA_PREFIX=C:\ProgramData\Anaconda3
CONDA_PROMPT_MODIFIER=(base)
CONDA_PYTHON_EXE=C:\ProgramData\Anaconda3\python.exe
CONDA_SHLVL=1
DriverData=C:\Windows\System32\Drivers\DriverData
FPS_BROWSER_APP_PROFILE_STRING=Internet Explorer
FPS_BROWSER_USER_PROFILE_STRING=Default
HOMEDRIVE=C:
...
OS=Windows_NT
Path=C:\ProgramData\Anaconda3;C:\ProgramData\Anaconda3\Library\mingw-w64\bin;C:\ProgramData\Anaconda3\Library\usr\bin;C:\ProgramData\Anaconda3\Library\bin;C:\ProgramData\Anaconda3\Scripts;C:\ProgramData\Anaconda3\bin;C:\ProgramData\Anaconda3\condabin;C:\Program Files\AdoptOpenJDK\jdk-11.0.8.10-hotspot\bin;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0;C:\windows\System32\OpenSSH;C:\Program Files\Microsoft VS Code\bin;C:\Program Files\Git\cmd;C:\Users\userme\AppData\Local\Microsoft\WindowsApps;C:\Program Files\Bandizip
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
platformcode=KV
PROCESSOR_ARCHITECTURE=AMD64
...
windir=C:\windows

CONDA_ 로 시작하는 변수들 몇 개가 더 정의 되었고, Path 에도 anaconda3 관련 경로가 추가 된 것들을 확인할 수 있다.

괜히 numpy, pandas 다시 깔거나 하는 삽질은 하지 않기를 바란다. anaconda 가 제공해 주는 편리한 환경을 한번 꼬이게 만들고, 향후 패키지 업데이트나 설치에 계속 문제를 발생시킬 수 있다.

728x90