Skip to content

Building on a mac

Matti Picus edited this page Jul 10, 2020 · 1 revision

(Draft)

Accumulated knowlege for building NumPy on a macOS machine. Please add your hints with a date

2020-07-10

Here is what I (mattip) think the numpy build does on Azure:

#!/bin/bash

function get_gfortran() {
    sudo xcode-select -s /Applications/Xcode_10.app/Contents/Developer
    curl -L https://github.com/MacPython/gfortran-install/raw/master/archives/gfortran-4.9.0-Mavericks.dmg -o gfortran.dmg
    GFORTRAN_SHA256=$(shasum -a 256 gfortran.dmg)
    KNOWN_SHA256="d2d5ca5ba8332d63bbe23a07201c4a0a5d7e09ee56f0298a96775f928c3c4b30  gfortran.dmg"
    if [ "$GFORTRAN_SHA256" != "$KNOWN_SHA256" ]; then
        echo sha256 mismatch
        exit 1  # crashes your shell, watch out
    fi
    hdiutil attach -mountpoint /Volumes/gfortran gfortran.dmg
    sudo installer -pkg /Volumes/gfortran/gfortran.pkg -target /
        otool -L /usr/local/gfortran/lib/libgfortran.3.dylib
    # Manually symlink gfortran-4.9 to plain gfortran for f2py.
    # No longer needed after Feb 13 2020 as gfortran is already present
    # and the attempted link errors. Keep this for future reference.
    # ln -s /usr/local/bin/gfortran-4.9 /usr/local/bin/gfortran
}

function get_openblas() {
    target=$(python tools/openblas_support.py)
    # manually link to appropriate system paths
    cp $target/lib/lib* /usr/local/lib/
    cp $target/include/* /usr/local/include/
    otool -L /usr/local/lib/libopenblas*
}

get_gfortran()
get_openblas()

python -m pip install -r test_requirements.txt
BLAS: None
LAPACK: None
ATLAS: None
CC: /usr/bin/clang
python setup.py build -j 4 build_src --verbose-cfg install