QuantLib-Python installation on Windows
Installation from PyPI (recommended)
If you don't need to modify the wrappers, you can install a
precompiled wheel from PyPI. Once you have activated the Python
environment you want to use, make sure you have the latest version
of pip
by running:
python -m pip install -U pip
(note that your Python interpreter might be named python3
instead) and then run:
python -m pip install QuantLib
If a wheel is available for your system (which is likely) 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, most likely in the x64 variant.
Setup
Before compiling the wrappers, you'll need to set up an appropriate environment. All of the following must be done in a command shell:
- Set the environment variables
QL_DIR
andINCLUDE
to the location of your QuantLib and Boost installations, respectively. Assuming, for example, that you installed Boost inC:\local\boost_1_86_0
and QuantLib inC:\local\QuantLib-1.36
, the commands would be:set QL_DIR=C:\local\QuantLib-1.36 set INCLUDE=C:\local\boost_1_86_0
- You'll need to install a few Python modules. It's good practice
to install them in a new virtual environment, to avoid possible
conflicts with your system Python installation. This also helps
in case you have multiple versions of Python on your machine. You
can create the virtual environment with
python3 -m venv .venv
and activate it with.\.venv\Scripts\activate
Once the environment is active, runpip install setuptools build tox pytest
If you're usingconda
to manage your environments, you know what to do instead. - Contrary to popular belief, working from a released tarball doesn't require you to have SWIG installed.
Compilation
You can download released QuantLib-SWIG versions from GitHub at https://github.com/lballabio/QuantLib-SWIG/releases. You should download the same version as the version of QuantLib you installed; for the sake of example, I'll use version 1.36 which is the most recent version at the time of this writing.
Once you have the zip file, extract it by executing
tar xzf QuantLib-SWIG-1.36.tar.gzThis creates a folder
QuantLib-SWIG-1.36
; enter
its Python
subfolder and build the QuantLib wrappers by
executing:
cd QuantLib-SWIG-1.36\Python python -m build wheel
This will create a binary wheel in the dist
directory.
To check that it works, run
tox run
from the Python
directory (you should already be there).
Once you're done, you can take the wheel and install it
with pip
in the environment of your choice.
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. . At the time of this writing, the wrappers use SWIG 4.3.0. Once SWIG is built and available in your path, run:
swig -python -c++ -outdir src\QuantLib -o src\QuantLib\quantlib_wrap.cpp ..\SWIG\quantlib.ifrom the
QuantLib-SWIG-1.36\Python
directory. The rest
of the installation goes as above.