XGBoost Library (libxgboost.dylib) could not be loaded.
Third-person routing text. Fixes xgboost failing on macOS with XGBoost Library (libxgboost.dylib) could not be loaded: the wheel needs the OpenMP runtime. brew install libomp, or install xgboost from conda-forge. Use when an agent hits this importing xgboost on macOS. Not for Linux or Windows.
TL;DR: the macOS xgboost wheel needs the OpenMP runtime and it is missing. Run brew install libomp, or install xgboost from conda-forge instead.
The error
XGBoost Library (libxgboost.dylib) could not be loaded.Fix it
Install the OpenMP runtime:
brew install libompExpected: installs libomp.dylib.
Verify:
python -c "import xgboost; print(xgboost.__version__)"Expected: prints the version, no error.
Alternative without Homebrew: use the conda-forge build, which handles OpenMP itself:
conda install -c conda-forge xgboost
When this applies
Use this when import xgboost on macOS raises the libxgboost.dylib load error, usually with the rpath libomp.dylib reference mentioned below it.
When it does not apply
On Linux the missing library is libgomp.so (a different fix). On Windows it is the vcomp DLL. If the error is an ImportError for a Python name instead, that is a separate issue.
Compatibility
macOS, pip-installed xgboost wheels.
Root cause
The macOS wheel links OpenMP dynamically against Homebrew's libomp path instead of bundling it. Without Homebrew's libomp installed, the dynamic loader cannot resolve the reference and the whole native library fails to load.
Edge cases
Apple-silicon and Intel Macs both need this; the brew path differs but brew install libomp handles either. In CI without brew, the conda-forge package is the reliable route.