QuantLib-Python installation on Mac OS X
The following assumes that you already installed QuantLib (but first, you might consider installing from PyPI; read below). 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.
Installation from PyPI
If you don't need to modify the wrappers, you might want to try installing a precompiled binary version. The availability of binaries depend on your operating system; to try to install them, run:
pip install QuantLib-Python
(note that the
pip executable might be
pip3 on your system). If a
binary package is available for your system, it will be installed and
you will be able to leave this page and use it right away; if not,
you'll have to compile it yourself as described in the next
Installation from a released version
You can download released QuantLib-SWIG versions from Bintray at https://bintray.com/quantlib/releases/QuantLib-SWIG.
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
QuantLib-SWIG-1.8; enter it and configure QuantLib
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 few caveats to the above. The first is
./configure command will need to
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
quantlib-config must be in your path. If you
installed QuantLib in
/usr/local like Homebrew or
/opt/local like MacPorts, you should be already set
The second is that the call
./configure as written above will find the system
installation of Python. If you want to use a different one (for
instance because you installed Python 3, or you want to use an
Anaconda installation) you must pass the location of your chosen
Python interpreter to
./configure; for instance, if you
have Python 3 installed as
have to run:
./configure PYTHON=/usr/local/bin/python3 CXXFLAGS=...
The third is that, unfortunately, at this
make install ignores any prefix you might pass
./configure and always installs to the default
location, which usually 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, 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
or a fork of it that you might have created) you'll need an additional
step at the beginning of the process. Before running
./configure script, you'll have to create it by
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.