Repository navigation
Expand file tree
/
Copy pathmacosx-python.shtml
More file actions
140 lines (124 loc) · 4.93 KB
/
Copy pathmacosx-python.shtml
File metadata and controls
140 lines (124 loc) · 4.93 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
---
layout: default
title: QuantLib-Python Installation on Mac OS X
---
<h1 class="center">QuantLib-Python installation on Mac OS X</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 are available
at <a href="https://www.quantlib.org/install/macosx.shtml">https://www.quantlib.org/install/macosx.shtml</a>.</p>
<h3>Setup</h3>
<p>Before compiling the wrappers, you'll need to set up an appropriate
environment:</p>
<ul>
<li>Some of the commands you'll run will need to
invoke <code>quantlib-config</code> (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 <code>quantlib-config</code> is in your executable path.</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/bin/activate
</pre>
(mind the single dot at the beginning of the line.) 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>You might have to set up a couple of environment variables:<br/>
<strong>on Mac OS X 10.11 (El Capitan) and later,</strong>
<pre>
export CXXFLAGS='-O2 -stdlib=libc++ -mmacosx-version-min=10.9'
export LDFLAGS='-stdlib=libc++ -mmacosx-version-min=10.9'
</pre>
<strong>on Mac OS X 10.9 (Mavericks) and 10.10 (Yosemite),</strong>
<pre>
export CXXFLAGS='-O2 -stdlib=libstdc++ -mmacosx-version-min=10.6'
export LDFLAGS='-stdlib=libstdc++ -mmacosx-version-min=10.6'
</pre>
<strong>on earlier systems,</strong>
<pre>
export CXXFLAGS='-O2'
</pre>
</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 tarball, 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 it and configure QuantLib by executing:
<pre>
cd QuantLib-SWIG-1.36
./configure
</pre>
<p>After configuration, you can run
<pre>
cd Python
make
</pre>
<p>This will create a binary wheel in the <code>dist</code> directory.
To check that it works, run</p>
<pre>
make check
</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. Before running
the <code>./configure</code> script, you'll have to create it by
executing</p>
<pre>
./autogen.sh
</pre>
<p>To do this, you'll need automake, autoconf and libtool; you can get them packaged from Homebrew or MacPorts.</p>
<p>After the execution of <code>./autogen.sh</code>, 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 <a href="http://swig.org">http://swig.org</a>. At the time of
this writing, the wrappers use SWIG 4.3.0.</p>