blob: 7847969f80d17afcd75c73b5547ba4c9a56d54a5 [file] [log] [blame]
Alex Gaynor84d5c6b2014-02-02 10:12:34 -08001Installation
2============
skeuomorfbc26efb2014-01-29 08:31:47 +02003
4You can install ``cryptography`` with ``pip``:
5
6.. code-block:: console
7
8 $ pip install cryptography
9
Alex Stapletonb4684172014-03-15 18:02:13 +000010Supported platforms
11-------------------
12
Alex Gaynora26c13a2015-09-25 17:52:06 -040013Currently we test ``cryptography`` on Python 2.6, 2.7, 3.3, 3.4, 3.5, and PyPy
142.6+ on these operating systems.
Alex Stapletonb4684172014-03-15 18:02:13 +000015
Paul Kehrer73667de2014-07-14 12:33:27 -050016* x86-64 CentOS 7.x, 6.4 and CentOS 5.x
Paul Kehrerbd88ee62015-02-20 10:38:31 -060017* x86-64 FreeBSD 10
Paul Kehrerda742982015-10-01 21:10:26 -050018* OS X 10.11 El Capitan, 10.10 Yosemite, 10.9 Mavericks, 10.8 Mountain Lion,
19 and 10.7 Lion
20* x86-64 Ubuntu 12.04 LTS and Ubuntu 14.04 LTS
21* x86-64 Debian Wheezy (7.x), Jessie (8.x), and Debian Sid (unstable)
22* 32-bit and 64-bit Python on 64-bit Windows Server 2012
Alex Stapletonb4684172014-03-15 18:02:13 +000023
Paul Kehrerfb8dcdb2014-04-20 19:25:18 -050024We test compiling with ``clang`` as well as ``gcc`` and use the following
25OpenSSL releases:
26
27* ``OpenSSL 0.9.8e-fips-rhel5`` (``RHEL/CentOS 5``)
Alex Stapleton2c688a42014-05-04 15:22:29 +010028* ``OpenSSL 0.9.8k``
Paul Kehrerda742982015-10-01 21:10:26 -050029* ``OpenSSL 0.9.8-latest`` (The most recent 0.9.8 release)
Paul Kehrerfb8dcdb2014-04-20 19:25:18 -050030* ``OpenSSL 1.0.0-fips`` (``RHEL/CentOS 6.4``)
31* ``OpenSSL 1.0.1``
Paul Kehrere683dee2014-08-09 08:15:23 -100032* ``OpenSSL 1.0.1e-fips`` (``RHEL/CentOS 7``)
Paul Kehrer96a08272015-02-21 18:37:38 -060033* ``OpenSSL 1.0.1j-freebsd``
Paul Kehrerda742982015-10-01 21:10:26 -050034* ``OpenSSL 1.0.1f``
35* ``OpenSSL 1.0.2-latest``
Paul Kehrerfb8dcdb2014-04-20 19:25:18 -050036
skeuomorfbc26efb2014-01-29 08:31:47 +020037On Windows
38----------
Alex Gaynor84d5c6b2014-02-02 10:12:34 -080039
Paul Kehrer156360a2014-06-30 12:14:01 -060040The wheel package on Windows is a statically linked build (as of 0.5) so all
41dependencies are included. Just run
42
43.. code-block:: console
44
45 $ pip install cryptography
46
47If you prefer to compile it yourself you'll need to have OpenSSL installed.
Paul Kehrer6608b7e2015-07-24 21:52:17 +010048You can compile OpenSSL yourself as well or use the binaries we build for our
49release infrastructure (`32-bit`_ and `64-bit`_). Wherever you place your copy
50of OpenSSL you'll need to set the ``LIB`` and ``INCLUDE`` environment variables
51to include the proper locations. For example:
skeuomorfbc26efb2014-01-29 08:31:47 +020052
skeuomorfb0293bf2014-01-29 21:41:02 +020053.. code-block:: console
54
55 C:\> \path\to\vcvarsall.bat x86_amd64
Paul Kehrer6608b7e2015-07-24 21:52:17 +010056 C:\> set LIB=C:\OpenSSL-win64\lib;%LIB%
57 C:\> set INCLUDE=C:\OpenSSL-win64\include;%INCLUDE%
Paul Kehrer2a39f7f2014-07-02 22:56:01 -050058 C:\> pip install cryptography
59
skeuomorfbc26efb2014-01-29 08:31:47 +020060
Cory Benfield6d447282015-10-07 14:50:50 +010061.. _build-on-linux:
62
Chris Glass2e15c7f2014-02-13 19:10:10 +010063Building cryptography on Linux
64------------------------------
Chris Glass87c4edb2014-02-13 09:34:21 +010065
Chris Glass2e15c7f2014-02-13 19:10:10 +010066``cryptography`` should build very easily on Linux provided you have a C
Alex Gaynor49923842014-02-13 10:32:56 -080067compiler, headers for Python (if you're not using ``pypy``), and headers for
68the OpenSSL and ``libffi`` libraries available on your system.
Chris Glass87c4edb2014-02-13 09:34:21 +010069
Ayrxd9702f92014-02-15 23:57:13 +080070For Debian and Ubuntu, the following command will ensure that the required
Chris Glassf82d94f2014-02-13 11:46:49 +010071dependencies are installed:
Chris Glass87c4edb2014-02-13 09:34:21 +010072
73.. code-block:: console
74
Alex Gaynor49923842014-02-13 10:32:56 -080075 $ sudo apt-get install build-essential libssl-dev libffi-dev python-dev
Chris Glass87c4edb2014-02-13 09:34:21 +010076
Ayrxd9702f92014-02-15 23:57:13 +080077For Fedora and RHEL-derivatives, the following command will ensure that the
78required dependencies are installed:
Ayrxa674c6b2014-02-15 21:24:23 +080079
80.. code-block:: console
81
82 $ sudo yum install gcc libffi-devel python-devel openssl-devel
83
Chris Glass87c4edb2014-02-13 09:34:21 +010084You should now be able to build and install cryptography with the usual
85
86.. code-block:: console
87
Alex Gaynor49923842014-02-13 10:32:56 -080088 $ pip install cryptography
Chris Glass87c4edb2014-02-13 09:34:21 +010089
Alex Gaynoreb50a2c2014-05-02 09:38:33 -070090
Chris Glass2e15c7f2014-02-13 19:10:10 +010091Using your own OpenSSL on Linux
92~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
skeuomorfbc26efb2014-01-29 08:31:47 +020093
94Python links to OpenSSL for its own purposes and this can sometimes cause
95problems when you wish to use a different version of OpenSSL with cryptography.
96If you want to use cryptography with your own build of OpenSSL you will need to
97make sure that the build is configured correctly so that your version of
98OpenSSL doesn't conflict with Python's.
99
100The options you need to add allow the linker to identify every symbol correctly
101even when multiple versions of the library are linked into the same program. If
102you are using your distribution's source packages these will probably be
103patched in for you already, otherwise you'll need to use options something like
104this when configuring OpenSSL:
105
106.. code-block:: console
107
108 $ ./config -Wl,--version-script=openssl.ld -Wl,-Bsymbolic-functions -fPIC shared
109
110You'll also need to generate your own ``openssl.ld`` file. For example::
111
112 OPENSSL_1.0.1F_CUSTOM {
113 global:
114 *;
115 };
116
117You should replace the version string on the first line as appropriate for your
118build.
119
Cory Benfield6d447282015-10-07 14:50:50 +0100120Static Wheels
121~~~~~~~~~~~~~
122
123Cryptography ships statically-linked wheels for OS X and Windows, ensuring that
124these platforms can always use the most-recent OpenSSL, regardless of what is
125shipped by default on those platforms. As a result of various difficulties
126around Linux binary linking, Cryptography cannot do the same on Linux.
127
128However, you can build your own statically-linked wheels that will work on your
129own systems. This will allow you to continue to use relatively old Linux
130distributions (such as LTS releases), while making sure you have the most
131recent OpenSSL available to your Python programs.
132
133To do so, you should find yourself a machine that is as similar as possible to
134your target environment (e.g. your production environment): for example, spin
135up a new cloud server running your target Linux distribution. On this machine,
136install the Cryptography dependencies as mentioned in :ref:`build-on-linux`.
137Please also make sure you have `virtualenv`_ installed: this should be
138available from your system package manager.
139
Cory Benfield80781842015-10-07 15:07:57 +0100140Then, paste the following into a shell script. You'll need to populate the
141``OPENSSL_VERSION`` variable. To do that, visit `openssl.org`_ and find the
142latest non-FIPS release version number, then set the string appropriately. For
143example, for OpenSSL 1.0.2d, use ``OPENSSL_VERSION="1.0.2d"``.
Cory Benfield6d447282015-10-07 14:50:50 +0100144
145When this shell script is complete, you'll find a collection of wheel files in
146a directory called ``wheelhouse``. These wheels can be installed by a
147sufficiently-recent version of ``pip``. The Cryptography wheel in this
148directory contains a statically-linked OpenSSL binding, which ensures that you
149have access to the most-recent OpenSSL releases without corrupting your system
150dependencies.
151
152.. code-block:: console
153
154 set -e
155
Cory Benfield80781842015-10-07 15:07:57 +0100156 OPENSSL_VERSION="VERSIONGOESHERE"
Cory Benfield6d447282015-10-07 14:50:50 +0100157 CWD=$(pwd)
158
159 virtualenv env
160 . env/bin/activate
161 pip install -U setuptools
162 pip install -U wheel pip
163 curl -O https://openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz
164 tar xvf openssl-${OPENSSL_VERSION}.tar.gz
165 cd openssl-${OPENSSL_VERSION}
166 ./config no-shared no-ssl2 -fPIC --prefix=${CWD}/openssl
167 make && make install
168 cd ..
Cory Benfield09d1b472015-10-16 08:14:42 +0100169 CFLAGS="-I${CWD}/openssl/include" LDFLAGS="-L${CWD}/openssl/lib" pip wheel --no-use-wheel cryptography
Cory Benfield6d447282015-10-07 14:50:50 +0100170
Paul Kehrer451c8df2015-07-04 11:03:27 -0500171Building cryptography on OS X
172-----------------------------
173
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500174The wheel package on OS X is a statically linked build (as of 1.0.1) so for
Paul Kehrer044c8dd2015-10-01 21:11:08 -0500175users on 10.10 (Yosemite) and above you only need one step:
Paul Kehrer451c8df2015-07-04 11:03:27 -0500176
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500177.. code-block:: console
skeuomorfbc26efb2014-01-29 08:31:47 +0200178
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500179 $ pip install cryptography
180
181If you want to build cryptography yourself or are on an older OS X version
182cryptography requires the presence of a C compiler, development headers, and
183the proper libraries. On OS X much of this is provided by Apple's Xcode
184development tools. To install the Xcode command line tools open a terminal
185window and run:
186
187.. code-block:: console
188
189 $ xcode-select --install
190
191This will install a compiler (clang) along with (most of) the required
192development headers.
193
194You'll also need OpenSSL, which you can obtain from `Homebrew`_ or `MacPorts`_.
195
196To build cryptography and dynamically link it:
Ayrx1ced5b82014-04-08 19:41:26 +0800197
198`Homebrew`_
skeuomorfbc26efb2014-01-29 08:31:47 +0200199
200.. code-block:: console
201
202 $ brew install openssl
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500203 $ env LDFLAGS="-L$(brew --prefix openssl)/lib" CFLAGS="-I$(brew --prefix openssl)/include" pip install cryptography
skeuomorfbc26efb2014-01-29 08:31:47 +0200204
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500205`MacPorts`_:
Kimmo Parviainen-Jalankoe01e0bf2014-03-19 18:57:09 +0200206
207.. code-block:: console
208
209 $ sudo port install openssl
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500210 $ env LDFLAGS="-L/opt/local/lib" CFLAGS="-I/opt/local/include" pip install cryptography
211
212You can also build cryptography statically:
213
214`Homebrew`_
215
216.. code-block:: console
217
218 $ brew install openssl
219 $ env CRYPTOGRAPHY_OSX_NO_LINK_FLAGS=1 LDFLAGS="$(brew --prefix openssl)/lib/libssl.a $(brew --prefix openssl)/lib/libcrypto.a" CFLAGS="-I$(brew --prefix openssl)/include" pip install cryptography
220
221`MacPorts`_:
222
223.. code-block:: console
224
225 $ sudo port install openssl
226 $ env CRYPTOGRAPHY_OSX_NO_LINK_FLAGS=1 LDFLAGS="/opt/local/lib/libssl.a /opt/local/lib/libcrypto.a" CFLAGS="-I/opt/local/include" pip install cryptography
skeuomorfbc26efb2014-01-29 08:31:47 +0200227
Alex Gaynoreb50a2c2014-05-02 09:38:33 -0700228Building cryptography with conda
229--------------------------------
230
Alex Gaynord6948382014-05-02 14:10:14 -0700231Because of a `bug in conda`_, attempting to install cryptography out of the box
David Reide162e262014-05-07 16:21:00 -0700232will result in an error. This can be resolved by setting the library path
233environment variable for your platform.
David Reide43861d2014-05-07 16:19:08 -0700234
235On OS X:
Alex Gaynord8fc2572014-05-02 10:33:36 -0700236
237.. code-block:: console
238
239 $ env DYLD_LIBRARY_PATH="$HOME/anaconda/lib" pip install cryptography
240
David Reid18563e62014-05-07 16:20:09 -0700241and on Linux:
David Reide43861d2014-05-07 16:19:08 -0700242
243.. code-block:: console
244
245 $ env LD_LIBRARY_PATH="$HOME/anaconda/lib" pip install cryptography
246
Alex Gaynord8fc2572014-05-02 10:33:36 -0700247You will need to set this variable every time you start Python. For more
Alex Gaynorf65cba22014-05-02 10:40:57 -0700248information, consult `Greg Wilson's blog post`_ on the subject.
Alex Gaynoreb50a2c2014-05-02 09:38:33 -0700249
250
skeuomorfbc26efb2014-01-29 08:31:47 +0200251.. _`Homebrew`: http://brew.sh
Alex Gaynor3197ab52015-10-02 06:33:11 -0700252.. _`MacPorts`: https://www.macports.org
Paul Kehrer6608b7e2015-07-24 21:52:17 +0100253.. _`32-bit`: https://jenkins.cryptography.io/job/openssl-win32-release/
254.. _`64-bit`: https://jenkins.cryptography.io/job/openssl-win64-release/
Alex Gaynord6948382014-05-02 14:10:14 -0700255.. _`bug in conda`: https://github.com/conda/conda-recipes/issues/110
Alex Gaynord8fc2572014-05-02 10:33:36 -0700256.. _`Greg Wilson's blog post`: http://software-carpentry.org/blog/2014/04/mr-biczo-was-right.html
Cory Benfieldba8f6382015-10-07 15:07:47 +0100257.. _virtualenv: https://virtualenv.pypa.io/en/latest/
Cory Benfield3ed8b812015-10-07 15:18:12 +0100258.. _openssl.org: https://openssl.org/source/