QuantLib-Python installation on Mac OS X

Luigi Ballabio


The following assumes that you already installed QuantLib. Instructions for that are available at http://quantlib.org/install/macosx.shtml. In particular, check that you have provided the required options and environment variables to ./configure.

QuantLib-Python Installation

Installation from a released version

You can download released QuantLib-SWIG versions from the SourceForge download page at http://sourceforge.net/projects/quantlib/files/; look for the files under the other languages folder in any of the versioned folders under QuantLib.

Once you have the tarball, extract it by executing:

tar xzf QuantLib-SWIG-1.8.tar.gz

(1.8 is the most recent version at the time of this writing; you might have downloaded another one, but take care to use one compatible with the version of QuantLib you installed.) This creates a folder QuantLib-SWIG-1.8; enter it and configure QuantLib by executing:

On Mac OS X 10.11 (El Capitan) and later,

  cd QuantLib-SWIG-1.8
  ./configure CXXFLAGS='-O2 -stdlib=libc++ -mmacosx-version-min=10.9'

On Mac OS X 10.9 (Mavericks) and 10.10 (Yosemite),

  cd QuantLib-SWIG-1.8
  ./configure CXXFLAGS='-O2 -stdlib=libstdc++ -mmacosx-version-min=10.6'

On earlier systems,

  cd QuantLib-SWIG-1.8
  ./configure CXXFLAGS='-O2'

Contrary to popular belief, working from a released tarball doesn't require you to have SWIG installed. After configuration, you can run

  make -C Python
  sudo make -C Python install

There are a couple of caveats to the above. The first is that the ./configure command will need to invoke quantlib-config (which was installed with QuantLib) to find out what flags should be passed to the compiler and linker; they will also include the additional include directories you might have specified when you built QuantLib, so you'll be covered even if you have, say, Boost in a non-standard place. This means that quantlib-config must be in your path. If you installed QuantLib in /usr/local like Homebrew or in /opt/local like MacPorts, you should be already set up.

The second is that, unfortunately, at this time make install ignores any prefix you might pass to ./configure and always installs to the default location, which requires you to use sudo as I wrote above. If you don't have admin rights, or if you want to install to a different location (for instance, an Anaconda virtualenv) you can run:

  cd Python
  python setup.py install --prefix=/your/desired/location
  cd ..
replacing /your/desired/location with the actual path where you want to install (if the path is protected, you might still need to use sudo to run the command).

Once you're done, you can try to run a few examples to check your installation. To do this, you can execute:

  make -C Python check

Installation from a git repository

If you want to compile from a checkout of a git repository (such as the official one at https://github.com/lballabio/quantlib-swig, or a fork of it that you might have created) you'll need an additional step at the beginning of the process. Before running the ./configure script, you'll have to create it by executing


To do this, you'll need automake, autoconf and libtool. They can be installed using either Homebrew or MacPorts.

After the execution of ./autogen.sh, the installation proceeds as in the previous section. Note, though, that in this case you'll need SWIG available; you can download and install it from http://swig.org or, again, get it packaged from Homebrew or MacPorts.