@@ -7,110 +7,134 @@ title: QuantLib-Python Installation on Mac OS X
77
88<h2>Installation from PyPI (recommended)</h2>
99
10- <p>If you don't need to modify the wrappers, you might want to try
11- installing a precompiled binary version. The availability of binaries
12- depend on your operating system; to try to install them, run:</p>
10+ <p>If you don't need to modify the wrappers, you can install a
11+ precompiled wheel from PyPI. Once you have activated the Python
12+ environment you want to use, make sure you have the latest version
13+ of <code>pip</code> by running:</p>
14+ <pre>
15+ python -m pip install -U pip
16+ </pre>
17+ <p>(note that your Python interpreter might be named <code>python3</code> instead) and then run:</p>
1318<pre>
1419 python -m pip install QuantLib
1520</pre>
16- <p>(If you have multiple versions of Python installed, run the above
17- with the one you want to use QuantLib with.) If a binary package is
18- available for your system, it will be installed and you will be able
19- to leave this page and use it right away; if not, you'll have to
20- compile it yourself as described in the next section.</p>
21+ <p>If a wheel is available for your system (which is likely)
22+ it will be installed and you will be able to leave this page and use
23+ it right away; if not, you'll have to compile it yourself as described
24+ in the next section.</p>
2125
2226<h2>Installation from a released version</h2>
2327
2428<p>The following assumes that you already installed
25- QuantLib. Instructions for that are available
26- at <a href="http://quantlib.org/install/macosx.shtml">http://quantlib.org/install/macosx.shtml</a>. In
27- particular, check that you have provided the required options and
28- environment variables to <tt>./configure</tt> and that you can execute
29- the <tt>quantlib-config</tt> script.</p>
29+ QuantLib; instructions are available
30+ at <a href="http://quantlib.org/install/macosx.shtml">http://quantlib.org/install/macosx.shtml</a>.</p>
3031
31- <p>You can download released QuantLib-SWIG versions from GitHub
32- at <a href="https://github.com/lballabio/QuantLib-SWIG/releases">https://github.com/lballabio/QuantLib-SWIG/releases</a>.</p>
32+ <h3>Setup</h3>
3333
34- <p>Once you have the tarball, extract it by executing:</p>
34+ <p>Before compiling the wrappers, you'll need to set up an appropriate
35+ environment:</p>
36+ <ul>
37+ <li>Some of the commands you'll run will need to
38+ invoke <code>quantlib-config</code> (which was installed with
39+ QuantLib) to find out what flags should be passed to the compiler
40+ and linker; they will also include the additional include
41+ directories you might have specified when you built QuantLib, so
42+ you'll be covered even if you have, say, Boost in a non-standard
43+ place. This means that you must ensure
44+ that <code>quantlib-config</code> is in your executable path.</li>
45+ <li>You'll need to install a few Python modules. It's good practice
46+ to install them in a new virtual environment, to avoid possible
47+ conflicts with your system Python installation. This also helps
48+ in case you have multiple versions of Python on your machine. You
49+ can create the virtual environment with
50+ <pre>
51+ python3 -m venv .venv
52+ </pre>
53+ and activate it with
3554<pre>
36- tar xzf QuantLib-SWIG-1.29.tar.gz
55+ . .venv/bin/activate
3756</pre>
38- <p>(1.29 is the most recent version at the time of this writing; you
39- might have downloaded another one, but take care to use one compatible
40- with the version of QuantLib you installed.) This creates a
41- folder <code>QuantLib-SWIG-1.29</code>; enter it and build QuantLib by
42- executing the following commands. For QuantLib 1.22 only, you will
43- also need to add <tt>-std=c++11</tt > to <tt>CXXFLAGS</tt>. Again ,
44- make sure that you can execute <tt>quantlib-config</tt> from the
45- terminal, since the <tt>setup.py</tt> build will call it to retrieve a
46- few required compilation flags.</p >
47- <p>< strong>On Mac OS X 10.11 (El Capitan) and later,</strong>
57+ (mind the single dot at the beginning of the line.) Once the
58+ environment is active, run
59+ <pre>
60+ pip install setuptools build tox pytest
61+ </pre>
62+ If you're using <code>conda</code > to manage your environments ,
63+ you know what to do instead.
64+ </li>
65+ <li>You might have to set up a couple of environment variables:<br/ >
66+ <strong>on Mac OS X 10.11 (El Capitan) and later,</strong>
4867<pre>
49- cd QuantLib-SWIG-1.29/Python
5068 export CXXFLAGS='-O2 -stdlib=libc++ -mmacosx-version-min=10.9'
5169 export LDFLAGS='-stdlib=libc++ -mmacosx-version-min=10.9'
52- python3 setup.py build
5370</pre>
54- </p>
55- <p><strong>On Mac OS X 10.9 (Mavericks) and 10.10 (Yosemite),</strong>
71+ <strong>on Mac OS X 10.9 (Mavericks) and 10.10 (Yosemite),</strong>
5672<pre>
57- cd QuantLib-SWIG-1.29/Python
5873 export CXXFLAGS='-O2 -stdlib=libstdc++ -mmacosx-version-min=10.6'
5974 export LDFLAGS='-stdlib=libstdc++ -mmacosx-version-min=10.6'
60- python3 setup.py build
6175</pre>
62- </p>
63- <p><strong>On earlier systems,</strong>
76+ <strong>on earlier systems,</strong>
6477<pre>
65- cd QuantLib-SWIG-1.29/Python
6678 export CXXFLAGS='-O2'
67- python3 setup.py build
6879</pre>
80+ </li>
81+ <li>Contrary to popular belief, working from a released
82+ tarball <strong>doesn't require you to have SWIG
83+ installed</strong>.</li>
84+ </ul>
85+
86+ <h3>Compilation</h3>
87+
88+ <p>You can download released QuantLib-SWIG versions from GitHub
89+ at <a href="https://github.com/lballabio/QuantLib-SWIG/releases">https://github.com/lballabio/QuantLib-SWIG/releases</a>.
90+ You should download the same version as the version of QuantLib you
91+ installed; for the sake of example, I'll use version 1.36 which is
92+ the most recent version at the time of this writing.
6993</p>
7094
71- <p>Contrary to popular belief, working from a released
72- tarball <strong>doesn't require you to have SWIG
73- installed</strong>. After building, you can run
95+ <p>Once you have the tarball, extract it by executing</p>
7496<pre>
75- python3 setup.py install
97+ tar xzf QuantLib-SWIG-1.36.tar.gz
7698</pre>
77- to perform a system installation; however, you might consider either passing an installation path, as in:
99+ This creates a folder <code>QuantLib-SWIG-1.36</code>;
100+ enter it and configure QuantLib by executing:
78101<pre>
79- python3 setup.py install --prefix=/your/desired/location
102+ cd QuantLib-SWIG-1.36
103+ ./configure
80104</pre>
81- or building a wheel with
105+
106+ <p>After configuration, you can run
82107<pre>
83- python3 setup.py bdist_wheel
108+ cd Python
109+ make
84110</pre>
85- and use it for installation in the location you want; this will
86- require the <tt>wheel</tt> package installed.</p>
87-
88- <p>Also, note that simply calling
89- <code>python3</code> as written above will find the first version of
90- Python in your path. If you want to use a different one (for instance
91- because you installed multiple versions of Python, or you want to use
92- an Anaconda installation) you must call your chosen Python
93- interpreter; for instance, if you have Python 3.9 installed
94- as <code>/Library/Frameworks/Python.framework/Versions/3.9/bin/python3</code>,
95- you'll have to run:</p>
111+ <p>This will create a binary wheel in the <code>dist</code> directory.
112+ To check that it works, run</p>
96113<pre>
97- CXXFLAGS='...' LDFLAGS='...' /Library/Frameworks/Python.framework/Versions/3.9/bin/python3 setup.py build
114+ make check
98115</pre>
116+ <p>from the <code>Python</code> directory (you should already be there).</p>
99117
100- <p>Once you're done, you can try to run a few examples to check your
101- installation. To do this, you can execute:</p>
102- <pre>
103- python3 setup.py test
104- </pre>
118+ <p>Once you're done, you can take the wheel and install it
119+ with <code>pip</code> in the environment of your choice.</p>
105120
106121
107122<h2>Installation from a git repository</h2>
108123
109124<p>If you want to compile from a checkout of a git repository (such as
110125the official one
111126at <a href="https://github.com/lballabio/quantlib-swig">https://github.com/lballabio/quantlib-swig</a>,
112- or a fork of it that you might have created) you'll need SWIG
113- available; you can download and install it
114- from <a href="http://swig.org">http://swig.org</a> or, again, get it
115- packaged from Homebrew or MacPorts.</p>
127+ or a fork of it that you might have created) you'll need an additional
128+ step at the beginning of the process. Before running
129+ the <code>./configure</code> script, you'll have to create it by
130+ executing</p>
131+ <pre>
132+ ./autogen.sh
133+ </pre>
134+ <p>To do this, you'll need automake, autoconf and libtool; you can get them packaged from Homebrew or MacPorts.</p>
135+ <p>After the execution of <code>./autogen.sh</code>, the installation
136+ proceeds as in the previous section. Note, though, that in this case
137+ you'll need SWIG available; you can download and install it
138+ from <a href="http://swig.org">http://swig.org</a>. At the time of
139+ this writing, the wrappers use SWIG 4.3.0.</p>
116140
0 commit comments