You are on page 1of 3

1/14/2018 QuantLib-Python installation on Mac OS X

 
 
A free/open-source library for quantitative nance

QuantLib-Python installation on Mac OS


X
Luigi Ballabio

Prerequisites
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.

QuantLib­Python Installation
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  called  pip2  or  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 section.

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,
http://quantlib.org/install/macosx-python.shtml 1/3
1/14/2018 QuantLib-Python installation on Mac OS X

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 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 the call to ./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 /usr/local/bin/python3, you'll have to run:

./configure PYTHON=/usr/local/bin/python3 CXXFLAGS=...

The  third  is  that,  unfortunately,  at  this  time  make install  ignores  any  prefix  you  might  pass  to
./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


http://quantlib.org/install/macosx-python.shtml 2/3
1/14/2018 QuantLib-Python installation on Mac OS X

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

./autogen.sh

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.

http://quantlib.org/install/macosx-python.shtml 3/3

You might also like