在 Apple M1 上导入 XGBoost 时出错?

问题描述

有没有人想出如何让 XGboost 与 Apple M1 配合使用?

我尝试了多种方法来修复它,但它不起作用。

我试过重新安装它; pip 和 pip3 以及 python -m pip 和 conda 安装; brew 安装 limpomp;酿造安装 gcc@8;下载源代码并在本地编译。

XGboost 似乎不适用于 Apple M1。

这是错误,当我在脚本中导入 xgboost 时会发生这种情况:

XGBoostError: XGBoost Library (libxgboost.dylib) Could not be loaded.
Likely causes:
  * OpenMP runtime is not installed (vcomp140.dll or libgomp-1.dll for Windows,libomp.dylib for Mac OSX,libgomp.so for Linux and other UNIX-like OSes). Mac OSX users: Run `brew install libomp` to install OpenMP runtime.
  * You are running 32-bit Python on a 64-bit OS
Error message(s): ['dlopen(/opt/anaconda3/envs/msc-env/lib/python3.8/site-packages/xgboost/lib/libxgboost.dylib,6): Library not loaded: /usr/local/opt/libomp/lib/libomp.dylib\n  Referenced from: /opt/anaconda3/envs/msc-env/lib/python3.8/site-packages/xgboost/lib/libxgboost.dylib\n  Reason: image not found']

解决方法

我在配备 Apple M1 芯片的 MacBook Pro(13 英寸,M1,2020 年)上遇到了同样的问题,幸运的是,经过数小时的研究,我得到了解决方案,您只需按照以下说明操作:

brew install libomp
conda install -c conda-forge py-xgboost
,

https://discuss.xgboost.ai/t/xgboost-on-apple-m1/2004/8

cherry 的回答对我有用:

确保安装了 gcc-6(和 g+±6),如果没有安装

brew install gcc
brew install cmake

然后,执行以下操作

git clone --recursive https://github.com/dmlc/xgboost
cd xgboost/
make -j4
cd python-package
python3 setup.py install

如果您正在使用 Anaconda 并且尚未配置要使用的路径 ~/anaconda/bin 中的二进制文件,然后将最后一行运行为

/path/to/anaconda/bin/python3 setup.py install