8

Has anyone figured out how to make XGboost work with Apple M1?

I have tried multiple things to fix it, but it does not work.

I have tried reinstalling it; pip and pip3 and python -m pip and conda install; brew install limpomp; brew install gcc@8; Downloading source code and compiling locally.

It seems XGboost does not work on Apple M1.

Here is the error, this occurs when I import xgboost in my script:

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

3 Answers3

7

i'd got the same issue on MacBook Pro (13-inch, M1, 2020) with chip Apple M1, fortunately after of hours of some researches i got the solution, you just follow the following instruction:

brew install libomp
conda install -c conda-forge py-xgboost
economy
  • 4,035
  • 6
  • 29
  • 37
borsaid
  • 81
  • 2
  • 2
4

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

How to install xgboost in python on MacOS?

A combination of the answer from cherry (first) and Christoffer (second) work for me with miniforge interpreter:

Make sure gcc-11 (and g+±11) is installed, if not do so with

brew install gcc@11
brew install cmake

Then, do the following

    git clone --recursive https://github.com/dmlc/xgboost
    mkdir xgboost/my_build
    cd xgboost/my_build
    CC=gcc-11 CXX=g++-11 cmake ..
    make -j4
    cd ../python_package
   /Users/xx/miniforge3/envs/MLEnv/bin/python setup.py install

With the path to you miniforge venv

0

I put Terminal in Rosetta mode first before installing brew. This way I'm essentially running intel version of the packages. I provided more details in this gist.

Oscar Chen
  • 559
  • 5
  • 11