--- layout: default title: QuantLib-Python Installation on Linux ---
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.
The following assumes that you already installed QuantLib; instructions are available at https://www.quantlib.org/install/linux.shtml
Before compiling the wrappers, you'll need to set up an appropriate environment:
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 you must ensure
that quantlib-config is in your executable path.python3 -m venv .venvand activate it with
. .venv/bin/activate(mind the single dot at the beginning of the line.) Once the environment is active, run
pip install setuptools build tox pytestIf you're using
conda to manage your environments,
you know what to do instead.
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 python3-devSimilar packages should be available for most other distributions.
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 tarball, extract it by executing
tar xzf QuantLib-SWIG-1.36.tar.gzThis creates a folder
QuantLib-SWIG-1.36;
enter it and configure QuantLib by executing:
cd QuantLib-SWIG-1.36 ./configure
After configuration, you can run
cd Python make
This will create a binary wheel in the dist directory.
To check that it works, run
make check
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.
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. 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. At the time of
this writing, the wrappers use SWIG 4.3.0.