Python에서 xgboost를 가져올 수 없습니다.

Python에서 xgboost를 가져올 수 없습니다.

Python 2.7.16용 pip를 사용하여 xgboost를 성공적으로 설치했습니다. (저는 macOS High Sierra에서 Homebrew를 사용하여 이 Python 버전을 설치했습니다.) 내 문제는 아래 오류 메시지에 따라 Python에서 xgboost를 가져올 수 없다는 것입니다.

mac-128644:~ user$ python
Python 2.7.16 (default, Apr 12 2019, 15:32:52) 
[GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.11.45.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import xgboost
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/xgboost/__init__.py", line 11, in <module>
    from .core import DMatrix, Booster
  File "/usr/local/lib/python2.7/site-packages/xgboost/core.py", line 163, in <module>
    _LIB = _load_lib()
  File "/usr/local/lib/python2.7/site-packages/xgboost/core.py", line 154, in _load_lib
    'Error message(s): {}\n'.format(os_error_list))
xgboost.core.XGBoostError: XGBoost Library (libxgboost.dylib) could not be loaded.
Likely causes:
  * OpenMP runtime is not installed (vcomp140.dll or libgomp-1.dll for Windows, libgomp.so for UNIX-like OSes)
  * You are running 32-bit Python on a 64-bit OS
Error message(s): ['dlopen(/usr/local/lib/python2.7/site-packages/xgboost/./lib/libxgboost.dylib, 6): Library not loaded: /usr/local/opt/gcc/lib/gcc/8/libgomp.1.dylib\n  Referenced from: /usr/local/lib/python2.7/site-packages/xgboost/./lib/libxgboost.dylib\n  Reason: no suitable image found.  Did find:\n\t/usr/local/lib/python2.7/site-packages/xgboost/./lib/libxgboost.dylib/libgomp.1.dylib: stat() failed with errno=20']

내 Python 버전과 OS가 모두 64비트인지 확인했으므로 문제는 확실히 두 번째 "가능한 원인"이 아닙니다. 나는 또한 OpenMP가 설치되어 있다고 확신합니다. 제 경우에는 지침을 찾아보고 brew install llvm설치가 성공적이었습니다. 또한 왜 찾을 수 없는지 잘 모르겠습니다 . 해당 디렉토리에 들어가서 잘 볼 /usr/local/lib/python2.7/site-packages/xgboost/./lib/libxgboost.dylib수 있기 때문입니다 . 나중에 메시지에서 그런 것 같습니다.cdlibxgboost.dylib했다찾았지만 여전히 오류가 발생합니까? 여기서 정확히 무슨 일이 일어나고 있으며, 이 오류를 해결하려면 어떻게 해야 합니까?

답변1

gcc를 설치하셨나요? 다음 단계를 시도해 볼 수 있습니다.

brew install gcc@8 그럼 해

brew switch gcc 8.3.0_2또는 버전이 설치된 후 마지막으로

brew link --overwrite gcc이것이 내 문제를 해결한 것 같았습니다.

답변2

귀하의 Python 인터프리터는 귀하가 Python 2.7을 사용하고 있다고 말하지만,pypi xgboost 프로젝트, Python 3.8 이상이 필요합니다.

관련 정보