Skip to content

Commit b8e54f4

Browse files
committed
Updated installation instructions for Python wrappers
1 parent f07d8c6 commit b8e54f4

File tree

4 files changed

+254
-211
lines changed

4 files changed

+254
-211
lines changed

install/linux-python.shtml

Lines changed: 83 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -5,100 +5,111 @@ title: QuantLib-Python Installation on Linux
55

66
<h1 class="center">QuantLib-Python installation on Linux</h1>
77

8-
<h2>Installation from PyPI</h2>
8+
<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, first make
13-
sure you have the latest version of <code>pip</code> by running:</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>
1414
<pre>
1515
python -m pip install -U pip
1616
</pre>
17-
<p>and then run:</p>
17+
<p>(note that your Python interpreter might be named <code>python3</code> instead) and then run:</p>
1818
<pre>
1919
python -m pip install QuantLib
2020
</pre>
21-
<p>(If you have multiple versions of Python installed, run the above
22-
with the one you want to use QuantLib with.) If a binary package is
23-
available for your system, it will be installed and you will be able
24-
to leave this page and use it right away; if not, you'll have to
25-
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>
2625

2726
<h2>Installation from a released version</h2>
2827

2928
<p>The following assumes that you already installed
30-
QuantLib. Instructions for that are available
31-
at <a href="http://quantlib.org/install/linux.shtml">http://quantlib.org/install/linux.shtml</a>;
32-
please make sure that you performed all listed steps.</p>
33-
34-
<p>You can download released QuantLib-SWIG versions from GitHub
35-
at <a href="https://github.com/lballabio/QuantLib-SWIG/releases">https://github.com/lballabio/QuantLib-SWIG/releases</a>.</p>
36-
37-
<p>Once you have the tarball, extract it by executing:</p>
29+
QuantLib; instructions are available
30+
at <a href="http://quantlib.org/install/linux.shtml">http://quantlib.org/install/linux.shtml</a></p>
31+
32+
<h3>Setup</h3>
33+
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
3850
<pre>
39-
tar xzf QuantLib-SWIG-1.7.tar.gz
51+
python3 -m venv .venv
4052
</pre>
41-
<p>(1.7 is the most recent version at the time of this writing; you
42-
might have downloaded another one.) This creates a
43-
folder <code>QuantLib-SWIG-1.7</code>; enter it and configure QuantLib by
44-
executing:</p>
53+
and activate it with
4554
<pre>
46-
cd QuantLib-SWIG-1.7
47-
./configure
55+
. .venv/bin/activate
4856
</pre>
49-
50-
<p>Contrary to popular belief, working from a released tarball doesn't
51-
require you to have SWIG installed. After configuration, you can just
52-
run</p>
57+
(mind the single dot at the beginning of the line.) Once the
58+
environment is active, run
5359
<pre>
54-
make -C Python
55-
sudo make -C Python install
60+
pip install setuptools build tox pytest
5661
</pre>
57-
58-
<p>There are a few of caveats to the above. <strong>The first</strong>
59-
is that the <code>./configure</code> command will need to
60-
invoke <code>quantlib-config</code> (which was installed with
61-
QuantLib) to find out what flags should be passed to the compiler and
62-
linker; they will also include the additional include directories you
63-
might have specified when you built QuantLib, so you'll be covered
64-
even if you have, say, Boost in a non-standard place. This means
65-
that <code>quantlib-config</code> must be in your path.</p>
66-
67-
<p><strong>The second</strong> is that the call
68-
to <code>./configure</code> as written above will find the system
69-
installation of Python. If you want to use a different one (for
70-
instance because you installed different Python versions, or you want to use an
71-
Anaconda installation) you must pass the location of your chosen
72-
Python interpreter to <code>./configure</code>; for instance, if you
73-
have Python 3.9 installed as <code>/usr/local/bin/python3.9</code>, you'll
74-
have to run:</p>
62+
If you're using <code>conda</code> to manage your environments,
63+
you know what to do instead.
64+
</li>
65+
<li>You'll also need the Python development files installed (that
66+
is, <code>python.h</code> and so on). They might be available by
67+
default; but if not, you'll have to figure out how to get them. On
68+
Ubuntu, for instance, you would install them with:
7569
<pre>
76-
./configure PYTHON=/usr/local/bin/python3.9
70+
sudo apt-get install python3-dev
7771
</pre>
72+
Similar packages should be available for most other
73+
distributions.</li>
74+
<li>Contrary to popular belief, working from a released
75+
tarball <strong>doesn't require you to have SWIG
76+
installed</strong>.</li>
77+
</ul>
78+
79+
<h3>Compilation</h3>
80+
81+
<p>You can download released QuantLib-SWIG versions from GitHub
82+
at <a href="https://github.com/lballabio/QuantLib-SWIG/releases">https://github.com/lballabio/QuantLib-SWIG/releases</a>.
83+
You should download the same version as the version of QuantLib you
84+
installed; for the sake of example, I'll use version 1.36 which is
85+
the most recent version at the time of this writing.
86+
</p>
7887

79-
<p><strong>The third</strong> is that, unfortunately, at this
80-
time <code>make install</code> ignores any prefix you might pass
81-
to <code>./configure</code> and always installs to the default
82-
location, which requires you to use <code>sudo</code> as I wrote
83-
above. If you don't have admin rights, you'll have to look into
84-
<code>Python/Makefile</code> and pass your prefix
85-
to <code>setup.py.</code></p>
86-
87-
<p>Of course, you'll also need the Python development files installed
88-
(that is, <code>python.h</code> and so on). They might be available by
89-
default; but if not, you'll have to figure out how to get them. On
90-
Ubuntu, for instance, you would install them with:</p>
88+
<p>Once you have the tarball, extract it by executing</p>
9189
<pre>
92-
sudo apt-get install python3-dev
90+
tar xzf QuantLib-SWIG-1.36.tar.gz
91+
</pre>
92+
This creates a folder <code>QuantLib-SWIG-1.36</code>;
93+
enter it and configure QuantLib by executing:
94+
<pre>
95+
cd QuantLib-SWIG-1.36
96+
./configure
9397
</pre>
94-
<p>Similar packages should be available for most other
95-
distributions.</p>
9698

97-
<p>Once you're done, you can try to run a few examples to check your
98-
installation. To do this, you can execute:</p>
99+
<p>After configuration, you can run
100+
<pre>
101+
cd Python
102+
make
103+
</pre>
104+
<p>This will create a binary wheel in the <code>dist</code> directory.
105+
To check that it works, run</p>
99106
<pre>
100-
make -C Python check
107+
make check
101108
</pre>
109+
<p>from the <code>Python</code> directory (you should already be there).</p>
110+
111+
<p>Once you're done, you can take the wheel and install it
112+
with <code>pip</code> in the environment of your choice.</p>
102113

103114

104115
<h2>Installation from a git repository</h2>
@@ -122,10 +133,7 @@ get them by running</p>
122133
<p>After the execution of <code>./autogen.sh</code>, the installation
123134
proceeds as in the previous section. Note, though, that in this case
124135
you'll need SWIG available; you can download and install it
125-
from <a href="http://swig.org">http://swig.org</a> or, again, get it
126-
packaged for your distribution. On Ubuntu, for instance, the
127-
corresponding command would be</p>
128-
<pre>
129-
sudo apt-get install swig
130-
</pre>
136+
from <a href="http://swig.org">http://swig.org</a>. At the time of
137+
this writing, the wrappers use SWIG 4.3.0.</p>
138+
131139

install/macosx-python.shtml

Lines changed: 90 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -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
110125
the official one
111126
at <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

install/pics/pywin/cmd.png

-53.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)