
Ich habe xgboost erfolgreich mit pip für Python 2.7.16 installiert (ich habe diese Python-Version mit Homebrew auf macOS High Sierra installiert). Mein Problem ist, dass ich xgboost nicht in Python importieren kann, wie die folgende Fehlermeldung zeigt:
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']
Ich habe sichergestellt, dass sowohl meine Python-Version als auch mein Betriebssystem 64-Bit sind, also liegt das Problem definitiv nicht an der zweiten „wahrscheinlichen Ursache“. Ich bin mir auch ziemlich sicher, dass ich OpenMP installiert habe: Ich habe nach Anweisungen gesucht, in meinem Fall würde ich das tun brew install llvm
und die Installation war erfolgreich. Ich bin mir auch nicht sicher, warum es anscheinend nicht gefunden werden kann /usr/local/lib/python2.7/site-packages/xgboost/./lib/libxgboost.dylib
, da ich cd
in dieses Verzeichnis gehen und libxgboost.dylib
alles einwandfrei sehen kann. Es sieht so aus, als ob es später in der Nachrichttatfinde es, aber wirft trotzdem einen Fehler aus? Was genau ist hier los und was kann ich tun, um diesen Fehler zu beheben?
Antwort1
Hast du gcc installiert? Du kannst die folgenden Schritte versuchen.
brew install gcc@8
dann mach
brew switch gcc 8.3.0_2
oder die Version installiert dann schließlich
brew link --overwrite gcc
das schien mein Problem behoben zu haben.
Antwort2
Ihr Python-Interpreter sagt, Sie sind in Python 2.7, aber lautpypi xgboost-Projekt, es erfordert Python 3.8 oder höher.