[python] numpy ImportError: DLL load failed: 지정된 모듈을 찾을 수 없습니다.

kodman ingzart·2022년 1월 3일
1
post-thumbnail

ㄹㅇ 시작이 반인 파이썬 환경 셋업

뻑킹 처음에는 사내 pc라 뭔가 또 설치가 잘 안된줄 알고 pip install과 conda install을 돌아가면서 삭제하고 설치하고를 몇 번 반복했는지 모르겠다.
파이썬 코드에서 에러를 띄워서 해당 환경 경로의 python.exe를 실행해 직접 import 찍었는데도 결과는 같았다.

>>> import numpy
대충가상환경경로\lib\site-packages\numpy\__init__.py:148: 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 "대충가상환경경로\lib\site-packages\numpy\core\__init__.py", line 22, in <module>
    from . import multiarray
  File "대충가상환경경로\lib\site-packages\numpy\core\multiarray.py", line 12, in <module>
    from . import overrides
  File "대충가상환경경로\lib\site-packages\numpy\core\overrides.py", line 7, in <module>
    from numpy.core._multiarray_umath import (
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 "대충가상환경경로\lib\site-packages\numpy\__init__.py", line 150, in <module>
    from . import core
  File "대충가상환경경로\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.7 from "대충가상환경경로\python.exe"
  * The NumPy version is: "1.21.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: 지정된 모듈을 찾을 수 없습니다.
  • The NumPy version is: "1.21.2"
    and make sure that they are the versions you expect.

를 보고 '너무 최신버전인가?'라 생각하며 삽질이 추가된 건 덤이다.


결론부터 말하면 범인은 환경변수

(내 경우에는) 역시 환경변수가 문제였다.
환경변수 등록 후 해당 python을 종료 후 재실행시켜야 됐던 걸 보면 다음에 환경변수 등록 후 안되는 경우가 생긴다면 IDE고 뭐고 다 종료했다가 실행해보고 정 안되면 윈도우 국룰인 PC 재부팅을 시도해보는게 좋을 것 같다.


동일 pc 로컬에 위치한 다른 환경에서의 numpy는 문제가 없는데 '해당 환경만' 안되는구나로 초점이 잡혔고, 삽질의 연속으로 조금 더 나아가 신규 생성하는 환경들은 다 안된다는 결론을 도출했다.
알고보니 새로 생성한 Anaconda 가상환경의 Lib 경로를 시스템 환경변수에 등록을 안해줬던 것이다.


심지어 구글에 "numpy ImportError: DLL load failed: 지정된 모듈을 찾을 수 없습니다."로 검색하면 제일 처음 나오는 글에 있었고,
그 글을 내가 이전에 읽었으며,
이전에도 한번 겪었던 문제였던 걸로 모자라 직접 pc 어딘가 메모장으로 기록도 해놨다는 도저히 참을 수 없는 상황.
이쯤되면 본투비빠가거나 최근 급증한 음주량으로 인한 알콜성 치매임을 의심하지 않을 수 없다.

>>> any([born_idiot, alcohol_related_dementia])
True

I'm optimistic, yes.
I like this environment variable,
except it sucks.


on Mac

구태여 맥에서는 어떤지 확인해봤다.

(TestCase0) ingzart@gangminjos-MacBook-Pro / % 대충아나콘다경로/TestCase0/bin/python
Python 3.9.7 (default, Sep 16 2021, 08:50:36) 
[Clang 10.0.0 ] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> 

잘 되네, 윈도우 환경 변수 때문이었던 걸로.

profile
An optimist who becomes pessimistic while working

0개의 댓글