Não é possível importar xgboost em Python

Não é possível importar xgboost em Python

Instalei o xgboost com sucesso usando pip para Python 2.7.16 (instalei esta versão do Python usando Homebrew no macOS High Sierra). Meu problema é que não consigo importar xgboost em Python, conforme mensagem de erro abaixo:

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']

Certifiquei-me de que minha versão do Python e meu sistema operacional sejam de 64 bits, então o problema definitivamente não é a segunda "causa provável". Também tenho certeza de que tenho o OpenMP instalado: procurando instruções, no meu caso eu faria brew install llvme a instalação foi bem-sucedida. Também não sei por que não consigo encontrar /usr/local/lib/python2.7/site-packages/xgboost/./lib/libxgboost.dylib, pois posso cdentrar nesse diretório e ver libxgboost.dylibmuito bem. Parece que mais tarde na mensagemfezencontrá-lo, mas ainda gera um erro? O que exatamente está acontecendo aqui e o que posso fazer para corrigir esse erro?

Responder1

Você instalou o gcc? Você pode tentar as seguintes etapas.

brew install gcc@8 então faça

brew switch gcc 8.3.0_2ou a versão instalada então finalmente

brew link --overwrite gccisso parecia ter resolvido meu problema.

Responder2

Seu interpretador Python diz que você está no Python 2.7, mas de acordo comprojeto pypi xgboost, requer Python 3.8 ou superior.

informação relacionada