QuantLib-Python installation on Linux

Luigi Ballabio


The following assumes that you already installed QuantLib. Instructions for that are available at http://quantlib.org/install/linux.shtml; please make sure that you performed all listed steps.

QuantLib-Python Installation

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.7.tar.gz

(1.7 is the most recent version at the time of this writing; you might have downloaded another one.) This creates a folder QuantLib-SWIG-1.7; enter it and configure QuantLib by executing:

  cd QuantLib-SWIG-1.7

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

  make -C Python
  sudo make -C Python install

There are a few 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.

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

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 requires you to use sudo as I wrote above. If you don't have admin rights, you'll have to look into Python/Makefile and pass your prefix to setup.py.

Of course, you'll also need the Python development files installed (that is, python.h and so on). They might be available by default; but if not, you'll have to figure out how to get them. On Ubuntu, for instance, you would install them with:

  sudo apt-get install python-dev

Similar packages should be available for most other distributions.

Once you're done, you can try to run a few examples to check your installation. To do this, you can simply 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. Again, they're packaged for most Linux distributions; on Ubuntu, you would get them by running

  sudo apt-get install automake autoconf libtool

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 for your distribution. On Ubuntu, for instance, the corresponding command would be

  sudo apt-get install swig