Repository navigation
Expand file tree
/
Copy pathwindows-python.shtml
More file actions
118 lines (105 loc) · 4.29 KB
/
Copy pathwindows-python.shtml
File metadata and controls
118 lines (105 loc) · 4.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
---
layout: default
title: QuantLib-Python Installation on Windows
---
<h1 class="center">QuantLib-Python installation on Windows</h1>
<h2>Installation from PyPI (recommended)</h2>
<p>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 <code>pip</code> by running:</p>
<pre>
python -m pip install -U pip
</pre>
<p>(note that your Python interpreter might be named <code>python3</code> instead) and then run:</p>
<pre>
python -m pip install QuantLib
</pre>
<p>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.</p>
<h2>Installation from a released version</h2>
<p>The following assumes that you already installed QuantLib;
instructions for that are available
at <a href="https://www.quantlib.org/install/vc10.shtml">https://www.quantlib.org/install/vc10.shtml</a>.
Note that QuantLib must be compiled in Release mode, most likely in
the x64 variant.</p>
<h3>Setup</h3>
<p>Before compiling the wrappers, you'll need to set up an appropriate
environment. All of the following must be done in a command shell:</p>
<ul>
<li>Set the environment variables <code>QL_DIR</code>
and <code>INCLUDE</code> to the location of your QuantLib and
Boost installations, respectively. Assuming, for example, that you
installed Boost in <code>C:\local\boost_1_86_0</code> and QuantLib
in <code>C:\local\QuantLib-1.36</code>, the commands would be:
<pre>
set QL_DIR=C:\local\QuantLib-1.36
set INCLUDE=C:\local\boost_1_86_0
</pre>
</li>
<li>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
<pre>
python3 -m venv .venv
</pre>
and activate it with
<pre>
.\.venv\Scripts\activate
</pre>
Once the environment is active, run
<pre>
pip install setuptools build tox pytest
</pre>
If you're using <code>conda</code> to manage your environments,
you know what to do instead.
</li>
<li>Contrary to popular belief, working from a released
tarball <strong>doesn't require you to have SWIG
installed</strong>.</li>
</ul>
<h3>Compilation</h3>
<p>You can download released QuantLib-SWIG versions from GitHub
at <a href="https://github.com/lballabio/QuantLib-SWIG/releases">https://github.com/lballabio/QuantLib-SWIG/releases</a>.
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.
</p>
<p>Once you have the zip file, extract it by executing</p>
<pre>
tar xzf QuantLib-SWIG-1.36.tar.gz
</pre>
This creates a folder <code>QuantLib-SWIG-1.36</code>; enter
its <code>Python</code> subfolder and build the QuantLib wrappers by
executing:
<pre>
cd QuantLib-SWIG-1.36\Python
python -m build --wheel
</pre>
<p>This will create a binary wheel in the <code>dist</code> directory.
To check that it works, run</p>
<pre>
tox run
</pre>
<p>from the <code>Python</code> directory (you should already be there).</p>
<p>Once you're done, you can take the wheel and install it
with <code>pip</code> in the environment of your choice.</p>
<h2>Installation from a git repository</h2>
<p>If you want to compile from a checkout of a git repository (such as
the official one
at <a href="https://github.com/lballabio/quantlib-swig">https://github.com/lballabio/quantlib-swig</a>,
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 <a href="http://swig.org">http://swig.org</a>. . At the time of
this writing, the wrappers use SWIG 4.3.0. Once SWIG is built and
available in your path, run:
<pre>
swig -python -c++ -outdir src\QuantLib -o src\QuantLib\quantlib_wrap.cpp ..\SWIG\quantlib.i
</pre>
from the <code>QuantLib-SWIG-1.36\Python</code> directory. The rest
of the installation goes as above.</p>