QuantLib-Python installation on Windows

Luigi Ballabio


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/vc9.shtml for Visual Studio 9 (2008) and at http://quantlib.org/install/vc10.shtml for Visual Studio 10 (2010) and later. Note that QuantLib must be compiled in Release mode.

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

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 Bintray at https://bintray.com/quantlib/releases/QuantLib-SWIG.

Once you have the zip file, extract it to obtain a folder with a name like QuantLib-SWIG-1.9 (1.9 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.)

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

If you have the version of Visual Studio corresponding to your Python installation, it's very likely that the Python setup infrastructure will find it without need for you to set up the additional configurations described in how-to posts across the web. The Visual Studio versions used to compile each Python version, and thus also recommended for compiling additional modules, are Visual Studio 9 (2008) for Python 2.7 and 3.0 to 3.2; Visual Studio 10 (2010) for Python 3.3 and 3.4; and Visual Studio 14 (2015) for Python 3.5 and later. Of course, you'll need QuantLib compiled with the same Visual Studio version; you'll also need it compiled as a 32-bit or 64-bit binary to match your Python installation.

To compile the Python module, open a command prompt, and enter the Python folder inside the folder you unzipped. Next, set the environment variables QL_DIR and INCLUDE to the location of your QuantLib and Boost installations, respectively. Assuming, for example, that you installed Boost in C:\local\boost_1_64_0, QuantLib in C:\local\QuantLib-1.9, and QuantLib-SWIG in C:\local\QuantLib-SWIG-1.9, the commands would be:

  cd C:\local\QuantLib-SWIG-1.9\Python
  set QL_DIR=C:\local\QuantLib-1.9
  set INCLUDE=C:\local\boost_1_64_0
Once you've done this, you can run the actual build command, which is:
  python setup.py build
The script will find the compiler and build the module. Again, this requires a specific version of Visual Studio as mentioned above.

Command prompt

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

  python setup.py test
Finally, the command
  python setup.py install
will deploy the compiled module to your Python installation directory.

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. In this case, you'll need SWIG available; you can download and install it from http://swig.org. Once SWIG is in your path, run:

  python setup.py wrap
from the Python directory in which you'll build the module. The rest of the installation goes as above.