简体   繁体   English

无法在 Python 中导入 xgboost

[英]Unable to import xgboost in Python

I have installed xgboost successfully using pip for Python 2.7.16 (I installed this Python version using Homebrew on macOS High Sierra).我已经使用 pip for Python 2.7.16 成功安装了 xgboost(我在 macOS High Sierra 上使用 Homebrew 安装了这个 Python 版本)。 My problem is that I'm unable to import xgboost in Python, as per the error message below:我的问题是我无法在 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']

I've made sure that both my Python version and OS are 64-bit, so the problem is definitely not the second "likely cause."我已经确保我的 Python 版本和操作系统都是 64 位的,所以这个问题绝对不是第二个“可能的原因”。 I'm also pretty sure I have OpenMP installed: looking up instructions, for my case I would do brew install llvm and the install was successful.我也很确定我已经安装了 OpenMP:查找说明,对于我的情况,我会执行brew install llvm并且安装成功。 I'm also not sure why it can't seem to find /usr/local/lib/python2.7/site-packages/xgboost/./lib/libxgboost.dylib , as I can cd into that directory and see libxgboost.dylib just fine.我也不确定为什么它似乎找不到/usr/local/lib/python2.7/site-packages/xgboost/./lib/libxgboost.dylib ,因为我可以cd进入该目录并查看libxgboost.dylib就好了。 It looks like later on in the message it did find it, but still throws an error?看起来稍后在消息中确实找到了它,但仍然抛出错误? What exactly is going on here, and what can I do to fix this error?这里到底发生了什么,我该怎么做才能解决这个错误?

Install xgboost first:首先安装 xgboost:

pip install xgboost

Then use:然后使用:

brew install libomp

At last:最后:

import xgboost as

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM