MacOS scipy build fails as apple's clang does not support OpenMP

Hello,

I was trying to build scipy from source following the docs. The only problem is, to use LLVM with OpenMP on Apple devices, you typically need to install the LLVM and libomp libraries via Homebrew, as the default Xcode compilers do not support OpenMP (See for manual download OpenMP on macOS with Xcode tools ).

I personally installed llvm and libomp using brew and set these env vars:

```
export LLVM_PREFIX=“/opt/homebrew/opt/llvm”
export CC=“$LLVM_PREFIX/bin/clang”
export CXX=“$LLVM_PREFIX/bin/clang++”

export CPPFLAGS=“-I$(brew --prefix libomp)/include”
export LDFLAGS=“-L$(brew --prefix libomp)/lib”
```
(These ensure -fopenmp is accepted and omp.h/libomp.dylib are found.)

I was just wondering if docs point it out and I missed some points? If not I think it might be worth adding to docs.

Also I’m not sure if this is the correct way, how do you guys build scipy on macOS systems?

Thanks.

It’s not just -fopenmp but -Xclang -fopenmp and also -lomp.

1 Like

There’s not really any use of openmp within scipy, and you shouldn’t need to use a compiler that uses openmp. System clang is sufficient.

1 Like

See e.g. Parallel execution support in SciPy — SciPy v1.16.2 Manual

Thanks!
I have very little idea why my build was failing/asking for OpenMP, but using a pixi managed env did the trick. Also something which we can include in docs + as an optional build process. I’ll be happy to open a PR if you agree.

Great suggestion :wink: I already have a PR ready to be merged for this at https://github.com/scipy/scipy/pull/23844.

(a more complete docs overhaul planned for the future)

This looks sufficient! Thanks for the efforts.

1 Like

I had the same problem on MacOS. Got around it by using spin build --with-accelerate instead of spin build.