Jack Chambers
Jack Chambers

Reputation: 21

Running QuantLib python on 'apple silicon' Macbook

I am trying to run Quantlib-Python on a Macbook with M1 processor (Big Sur v11.3) following https://www.quantlib.org/install/macosx-python.shtml. I have managed to install Quantlib 1.22 and Python 3.9.4 via homebrew:

Pouring quantlib--1.22.arm64_big_sur.bottle.tar.gz into "/opt/homebrew/Cellar/quantlib/1.22"

However when I then try to install Quantlib-Python through pip I get:

ERROR: Could not find a version that satisfies the requirement QuantLib (from versions: none)
ERROR: No matching distribution found for QuantLib

From this it seems that whilst Quantlib 1.22 is ready for arm-based OSX, QuantLib-Python isn't.

Then I am trying to install from a released version as per the above link:

tar xzf QuantLib-SWIG-1.22.tar.gz
cd QuantLib-SWIG-1.22/Python
export CXXFLAGS='-O2 -std=c++11 -stdlib=libc++ -mmacosx-version-min=10.9'
export LDFLAGS='-stdlib=libc++ -mmacosx-version-min=10.9'
python setup.py build

But I get the following error:

cd QuantLib-SWIG-1.22/Python
  export CXXFLAGS='-O2 -std=c++11 -stdlib=libc++ -mmacosx-version-min=10.9'
  export LDFLAGS='-stdlib=libc++ -mmacosx-version-min=10.9'
  python setup.py build
running build
running build_py
running build_ext
building 'QuantLib._QuantLib' extension
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include -DNDEBUG -I/Users/USER/coding/project1/include -I/Users/USER/.pyenv/versions/3.9.4/include/python3.9 -I/opt/homebrew/Cellar/quantlib/1.22/include -c QuantLib/quantlib_wrap.cpp -o build/temp.macosx-11.3-arm64-3.9/QuantLib/quantlib_wrap.o -Wno-unused -O2 -std=c++11 -stdlib=libc++ -mmacosx-version-min=10.9
In file included from QuantLib/quantlib_wrap.cpp:4730:
In file included from /opt/homebrew/Cellar/quantlib/1.22/include/ql/version.hpp:28:
/opt/homebrew/Cellar/quantlib/1.22/include/ql/qldefines.hpp:38:10: fatal error: 'boost/config.hpp' file not found
#include <boost/config.hpp>
         ^~~~~~~~~~~~~~~~~~
1 error generated.
error: command '/usr/bin/clang' failed with exit code 1

I have tried quite a few workarounds for the boost issue, and looked over lots of other question/answers but yet to find a fix. Is it an issue with the flags? Has anyone had any luck getting QuantLib-Python to work on M1-based OSX?

Upvotes: 2

Views: 907

Answers (1)

peng
peng

Reputation: 21

Below worked for me on a MBP M1 Max:

  1. brew install boost

  2. brew install quantlib

  3. download QuantLib-SWIG-1.24.tar

    tar xzfv QuantLib-SWIG-1.24.tar

  4. cd QuantLib-SWIG-1.24/Python

    export CXXFLAGS='-O2 -std=c++11 -stdlib=libc++ -mmacosx-version-min=10.9 -I/opt/homebrew/Cellar/boost/1.76.0/include'

    export LDFLAGS='-stdlib=libc++ -mmacosx-version-min=10.9 -L/opt/homebrew/Cellar/boost/1.76.0/lib'

  5. python setup.py build

    python setup.py bdist_wheel

  6. cd dist

    pip install QuantLib-1.24-cp310-cp310-macosx_11_0_arm64.whl

Upvotes: 2

Related Questions