Skip to content

DOC: Update macOS Homebrew libomp instructions for Apple Silicon #31369

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions doc/developers/advanced_installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -280,16 +280,30 @@ Install the LLVM OpenMP library:

brew install libomp

Set the following environment variables:
Note: `libomp` is marked as "keg-only" in Homebrew, meaning it is not symlinked into standard system paths. Therefore, you need to explicitly set environment variables to inform the compiler and linker where to find `libomp`.

.. prompt:: bash $
The installation path of `libomp` depends on your Mac's architecture:

- **Intel-based Macs**: Homebrew installs packages under `/usr/local/opt/`
- **Apple Silicon (M1/M2) Macs**: Homebrew installs packages under `/opt/homebrew/opt/`

To determine the correct path, you can use the following command:

.. prompt:: bash

brew --prefix libomp

Set the following environment variables accordingly:

.. prompt:: bash

export CC=/usr/bin/clang
export CXX=/usr/bin/clang++
export CPPFLAGS="$CPPFLAGS -Xpreprocessor -fopenmp"
export CFLAGS="$CFLAGS -I/usr/local/opt/libomp/include"
export CXXFLAGS="$CXXFLAGS -I/usr/local/opt/libomp/include"
export LDFLAGS="$LDFLAGS -Wl,-rpath,/usr/local/opt/libomp/lib -L/usr/local/opt/libomp/lib -lomp"
export CC=/usr/bin/clang
export CXX=/usr/bin/clang++
export CPPFLAGS="$CPPFLAGS -Xpreprocessor -fopenmp"
export CFLAGS="$CFLAGS -I$(brew --prefix libomp)/include"
export CXXFLAGS="$CXXFLAGS -I$(brew --prefix libomp)/include"
export LDFLAGS="$LDFLAGS -L$(brew --prefix libomp)/lib -lomp"
export DYLD_LIBRARY_PATH=$(brew --prefix libomp)/lib

Finally, build scikit-learn in verbose mode (to check for the presence of the
``-fopenmp`` flag in the compiler commands):
Expand Down