개발

맥북 m1 jupyter notebook scikit-learn Import Error: | 주피터 노트북 사이킷 런 임포트 에러

콘2조아 2022. 4. 21. 00:34

주피터 노트북에서 sklearn 라이브러리를 사용하려다가 다음 Import Error가 났다.

ImportError: dlopen(/opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/scipy/spatial/qhull.cpython-39-darwin.so, 0x0002): Library not loaded: @rpath/liblapack.3.dylib   Referenced from: /opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/scipy/spatial/qhull.cpython-39-darwin.so

https://developer.apple.com/forums/thread/693696

 

Sklearn is unstable on Apple Silic… | Apple Developer Forums

Hi, Can you paste pip list when it runs successfully vs when it fails ? Also in your Jupyter cells, are you installing any packages or changing PYTHONPATH? If you could provide a small repro case, that might help give some idea.

developer.apple.com

여기서 한 해결책으로 제시해 준 것이

pip install --upgrade --force-reinstall scikit-learn

이 방법이다.

 

이 방법을 시도해 보니

ImportError: cannot import name '_FunctionWrapper' from 'scipy._lib._util' (/opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/scipy/_lib/_util.py)

라는 새로운 오류가 생겼다. 다시 이 오류를 가지고 구글에 검색해 봤다.

 

https://github.com/stellargraph/stellargraph/issues/1784

 

ImportError: cannot import name 'rng_integers' from 'scipy._lib._util' · Issue #1784 · stellargraph/stellargraph

Describe the bug Hi! Thank you for this great library. I'm trying to install Stellargraph on Ubuntu 18.04. However, after I successfully installed Stellargraph via conda (follow this instructio...

github.com

오류가 발생한 맥락이 약간 다르긴한데, 이런 오류는 scikit-learn 이 제대로 설치되지 않아서 생긴 것 같다는 식으로 설명한다.

그래서 그냥 scikit-learn을 재설치해보기로 했다.

 

터미널에

pip uninstall scikit-learn
pip install scikit-learn

이렇게 하니 문제가 간단하게 해결되었다. 다음에도 라이브러리에 문제가 생긴다면 재설치부터 시도해보자.