QuantLib-Python installation on Windows
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
(If you have multiple versions of Python installed, run the above with the one you want to use QuantLib with.) 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
The following assumes that you already installed QuantLib. Instructions for that are available at http://quantlib.org/install/vc10.shtml. Note that QuantLib must be compiled in Release mode.
You can download released QuantLib-SWIG versions from GitHub at https://github.com/lballabio/QuantLib-SWIG/releases.
Once you have the zip file, extract it to obtain a folder with a
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
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
the location of your QuantLib and Boost installations,
respectively. Assuming, for example, that you installed Boost
C:\local\QuantLib-1.9, and QuantLib-SWIG
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_0Once you've done this, you can run the actual build command, which is:
python setup.py buildThe script will find the compiler and build the module. Again, this requires a specific version of Visual Studio as mentioned above.
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 testFinally, the command
python setup.py installwill 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 wrapfrom the Python directory in which you'll build the module. The rest of the installation goes as above.