QuantLib-Python installation on Linux

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, first make sure you have the latest version of pip by running:

  python -m pip install -U pip

and then run:

  python -m 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/linux.shtml; please make sure that you performed all listed steps.

You can download released QuantLib-SWIG versions from GitHub at https://github.com/lballabio/QuantLib-SWIG/releases.

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
  ./configure

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 different Python versions, 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.9 installed as /usr/local/bin/python3.9, you'll have to run:

  ./configure PYTHON=/usr/local/bin/python3.9

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 python3-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 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

  ./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 or, again, get it packaged for your distribution. On Ubuntu, for instance, the corresponding command would be

  sudo apt-get install swig