blob: 35bfbbafe192363cac1da6c250bdf67870ca65ae [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
Paul Kehrer4cf6e782017-10-12 06:06:01 +080013Currently we test ``cryptography`` on Python 2.7, 3.4, 3.5, 3.6, and
Paul Kehrer6a10b292017-05-27 19:32:26 -050014PyPy 5.3+ on these operating systems.
Alex Stapletonb4684172014-03-15 18:02:13 +000015
Paul Kehrer6a10b292017-05-27 19:32:26 -050016* x86-64 CentOS 7.x
17* x86-64 FreeBSD 11
Alex Gaynore6859232017-09-26 20:03:53 -040018* macOS 10.12 Sierra, 10.11 El Capitan
Paul Kehrer6a10b292017-05-27 19:32:26 -050019* x86-64 Ubuntu 14.04, 16.04, and rolling
20* x86-64 Debian Wheezy (7.x), Jessie (8.x), Stretch (9.x), and Sid (unstable)
Paul Kehrer1eeaabb2017-07-01 17:34:36 -050021* x86-64 Alpine (latest)
Paul Kehrerda742982015-10-01 21:10:26 -050022* 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
Paul Kehrerfb8dcdb2014-04-20 19:25:18 -050027* ``OpenSSL 1.0.1``
Paul Kehrere683dee2014-08-09 08:15:23 -100028* ``OpenSSL 1.0.1e-fips`` (``RHEL/CentOS 7``)
Paul Kehrerda742982015-10-01 21:10:26 -050029* ``OpenSSL 1.0.1f``
Alex Gaynora5094962017-07-03 18:00:52 -040030* ``OpenSSL 1.0.1j-freebsd``
Paul Kehrerda742982015-10-01 21:10:26 -050031* ``OpenSSL 1.0.2-latest``
Alex Gaynor7a158272016-12-18 16:49:47 -050032* ``OpenSSL 1.1.0-latest``
Paul Kehrerfb8dcdb2014-04-20 19:25:18 -050033
Nick Badger63bbf182016-09-03 10:10:36 -070034Building cryptography on Windows
35--------------------------------
Alex Gaynor84d5c6b2014-02-02 10:12:34 -080036
Paul Kehrer156360a2014-06-30 12:14:01 -060037The wheel package on Windows is a statically linked build (as of 0.5) so all
Nick Badger63bbf182016-09-03 10:10:36 -070038dependencies are included. To install ``cryptography``, you will typically
39just run
Paul Kehrer156360a2014-06-30 12:14:01 -060040
41.. code-block:: console
42
43 $ pip install cryptography
44
45If you prefer to compile it yourself you'll need to have OpenSSL installed.
Paul Kehrer6608b7e2015-07-24 21:52:17 +010046You can compile OpenSSL yourself as well or use the binaries we build for our
Paul Kehrer937aa472015-10-11 12:09:27 -050047release infrastructure (`openssl-release`_). Be sure to download the proper
Paul Kehrer4cf6e782017-10-12 06:06:01 +080048version for your architecture and Python (2010 works for Python 2.7, 3.3,
Paul Kehrerf19fef12017-02-09 13:53:44 +080049and 3.4 while 2015 is required for 3.5 and above). Wherever you place your copy
Paul Kehrer6608b7e2015-07-24 21:52:17 +010050of 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
Paul Kehrerf19fef12017-02-09 13:53:44 +080060As of OpenSSL 1.1.0 the library names have changed from ``libeay32`` and
61``ssleay32`` to ``libcrypto`` and ``libssl`` (matching their names on all other
Paul Kehreradeaacf2017-05-24 12:49:18 -070062platforms). ``cryptography`` links against the new 1.1.0 names by default. If
63you need to compile ``cryptography`` against an older version then you **must**
64set ``CRYPTOGRAPHY_WINDOWS_LINK_LEGACY_OPENSSL`` or else installation will fail.
Paul Kehrerf19fef12017-02-09 13:53:44 +080065
Paul Kehrerd4ea53b2015-12-31 19:48:32 -060066If you need to rebuild ``cryptography`` for any reason be sure to clear the
67local `wheel cache`_.
skeuomorfbc26efb2014-01-29 08:31:47 +020068
Cory Benfield6d447282015-10-07 14:50:50 +010069.. _build-on-linux:
70
Chris Glass2e15c7f2014-02-13 19:10:10 +010071Building cryptography on Linux
72------------------------------
Chris Glass87c4edb2014-02-13 09:34:21 +010073
Paul Kehrer1eeaabb2017-07-01 17:34:36 -050074``cryptography`` ships a ``manylinux1`` wheel (as of 2.0) so all dependencies
75are included. For users on pip 8.1 or above running on a ``manylinux1``
76compatible distribution (almost everything except Alpine) all you should
77need to do is:
Chris Glass87c4edb2014-02-13 09:34:21 +010078
79.. code-block:: console
80
Paul Kehrer1eeaabb2017-07-01 17:34:36 -050081 $ pip install cryptography
Chris Glass87c4edb2014-02-13 09:34:21 +010082
Paul Kehrer1eeaabb2017-07-01 17:34:36 -050083If you are on Alpine or just want to compile it yourself then
84``cryptography`` requires a compiler, headers for Python (if you're not
85using ``pypy``), and headers for the OpenSSL and ``libffi`` libraries
86available on your system.
87
88Alpine
89~~~~~~
90
91Replace ``python3-dev`` with ``python-dev`` if you're using Python 2.
92
93.. code-block:: console
94
95 $ sudo apk add gcc musl-dev python3-dev libffi-dev openssl-dev
96
97If you get an error with ``openssl-dev`` you may have to use ``libressl-dev``.
98
99Debian/Ubuntu
100~~~~~~~~~~~~~
101
102Replace ``python3-dev`` with ``python-dev`` if you're using Python 2.
103
104.. code-block:: console
105
106 $ sudo apt-get install build-essential libssl-dev libffi-dev python3-dev
107
108RHEL/CentOS
109~~~~~~~~~~~
Ayrxa674c6b2014-02-15 21:24:23 +0800110
111.. code-block:: console
112
Alex Gaynord58c6ad2017-07-14 08:04:18 -0400113 $ sudo yum install redhat-rpm-config gcc libffi-devel python-devel \
114 openssl-devel
Ayrxa674c6b2014-02-15 21:24:23 +0800115
Paul Kehrer1eeaabb2017-07-01 17:34:36 -0500116
117Building
118~~~~~~~~
119
120You should now be able to build and install cryptography. To avoid getting
121the pre-built wheel on ``manylinux1`` distributions you'll need to use
122``--no-binary``.
Chris Glass87c4edb2014-02-13 09:34:21 +0100123
124.. code-block:: console
125
Paul Kehrer1eeaabb2017-07-01 17:34:36 -0500126 $ pip install cryptography --no-binary cryptography
Chris Glass87c4edb2014-02-13 09:34:21 +0100127
Alex Gaynoreb50a2c2014-05-02 09:38:33 -0700128
Chris Glass2e15c7f2014-02-13 19:10:10 +0100129Using your own OpenSSL on Linux
130~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
skeuomorfbc26efb2014-01-29 08:31:47 +0200131
132Python links to OpenSSL for its own purposes and this can sometimes cause
133problems when you wish to use a different version of OpenSSL with cryptography.
134If you want to use cryptography with your own build of OpenSSL you will need to
135make sure that the build is configured correctly so that your version of
136OpenSSL doesn't conflict with Python's.
137
138The options you need to add allow the linker to identify every symbol correctly
139even when multiple versions of the library are linked into the same program. If
140you are using your distribution's source packages these will probably be
141patched in for you already, otherwise you'll need to use options something like
142this when configuring OpenSSL:
143
144.. code-block:: console
145
146 $ ./config -Wl,--version-script=openssl.ld -Wl,-Bsymbolic-functions -fPIC shared
147
148You'll also need to generate your own ``openssl.ld`` file. For example::
149
Alex Gaynor46c0c622017-03-22 22:56:26 -0400150 OPENSSL_1.1.0E_CUSTOM {
skeuomorfbc26efb2014-01-29 08:31:47 +0200151 global:
152 *;
153 };
154
155You should replace the version string on the first line as appropriate for your
156build.
157
Cory Benfield6d447282015-10-07 14:50:50 +0100158Static Wheels
159~~~~~~~~~~~~~
160
Paul Kehrerf92f2d42017-07-04 16:00:08 -0500161Cryptography ships statically-linked wheels for macOS, Windows, and Linux (via
162``manylinux1``). This allows compatible environments to use the most recent
163OpenSSL, regardless of what is shipped by default on those platforms. Some
164Linux distributions (most notably Alpine) are not ``manylinux1`` compatible so
165we cannot distribute wheels for them.
Cory Benfield6d447282015-10-07 14:50:50 +0100166
167However, you can build your own statically-linked wheels that will work on your
168own systems. This will allow you to continue to use relatively old Linux
169distributions (such as LTS releases), while making sure you have the most
170recent OpenSSL available to your Python programs.
171
172To do so, you should find yourself a machine that is as similar as possible to
173your target environment (e.g. your production environment): for example, spin
174up a new cloud server running your target Linux distribution. On this machine,
175install the Cryptography dependencies as mentioned in :ref:`build-on-linux`.
176Please also make sure you have `virtualenv`_ installed: this should be
177available from your system package manager.
178
Cory Benfield80781842015-10-07 15:07:57 +0100179Then, paste the following into a shell script. You'll need to populate the
180``OPENSSL_VERSION`` variable. To do that, visit `openssl.org`_ and find the
181latest non-FIPS release version number, then set the string appropriately. For
Alex Gaynor46c0c622017-03-22 22:56:26 -0400182example, for OpenSSL 1.0.2k, use ``OPENSSL_VERSION="1.0.2k"``.
Cory Benfield6d447282015-10-07 14:50:50 +0100183
184When this shell script is complete, you'll find a collection of wheel files in
185a directory called ``wheelhouse``. These wheels can be installed by a
186sufficiently-recent version of ``pip``. The Cryptography wheel in this
187directory contains a statically-linked OpenSSL binding, which ensures that you
188have access to the most-recent OpenSSL releases without corrupting your system
189dependencies.
190
191.. code-block:: console
192
193 set -e
194
Cory Benfield80781842015-10-07 15:07:57 +0100195 OPENSSL_VERSION="VERSIONGOESHERE"
Cory Benfield6d447282015-10-07 14:50:50 +0100196 CWD=$(pwd)
197
198 virtualenv env
199 . env/bin/activate
200 pip install -U setuptools
201 pip install -U wheel pip
Matt Thomasa187c972016-10-03 17:48:31 -0400202 curl -O https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz
Cory Benfield6d447282015-10-07 14:50:50 +0100203 tar xvf openssl-${OPENSSL_VERSION}.tar.gz
204 cd openssl-${OPENSSL_VERSION}
Alex Gaynor46c0c622017-03-22 22:56:26 -0400205 ./config no-shared no-ssl2 no-ssl3 -fPIC --prefix=${CWD}/openssl
Cory Benfield6d447282015-10-07 14:50:50 +0100206 make && make install
207 cd ..
Cory Benfield09d1b472015-10-16 08:14:42 +0100208 CFLAGS="-I${CWD}/openssl/include" LDFLAGS="-L${CWD}/openssl/lib" pip wheel --no-use-wheel cryptography
Cory Benfield6d447282015-10-07 14:50:50 +0100209
Paul Kehrer524e7452017-03-09 19:18:24 -0400210Building cryptography on macOS
211------------------------------
Paul Kehrer451c8df2015-07-04 11:03:27 -0500212
Paul Kehrera17d5902016-03-20 22:29:17 -0400213.. note::
214
215 If installation gives a ``fatal error: 'openssl/aes.h' file not found``
216 see the :doc:`FAQ </faq>` for information about how to fix this issue.
217
Paul Kehrer524e7452017-03-09 19:18:24 -0400218The wheel package on macOS is a statically linked build (as of 1.0.1) so for
Paul Kehrera17d5902016-03-20 22:29:17 -0400219users with pip 8 or above you only need one step:
Paul Kehrer451c8df2015-07-04 11:03:27 -0500220
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500221.. code-block:: console
skeuomorfbc26efb2014-01-29 08:31:47 +0200222
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500223 $ pip install cryptography
224
Paul Kehrer524e7452017-03-09 19:18:24 -0400225If you want to build cryptography yourself or are on an older macOS version,
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500226cryptography requires the presence of a C compiler, development headers, and
Paul Kehrer524e7452017-03-09 19:18:24 -0400227the proper libraries. On macOS much of this is provided by Apple's Xcode
228development tools. To install the Xcode command line tools (on macOS 10.9+)
Paul Kehrerb29f4642015-12-31 23:27:25 -0600229open a terminal window and run:
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500230
231.. code-block:: console
232
233 $ xcode-select --install
234
235This will install a compiler (clang) along with (most of) the required
236development headers.
237
238You'll also need OpenSSL, which you can obtain from `Homebrew`_ or `MacPorts`_.
Paul Kehrer355174a2015-12-22 09:47:26 -0600239Cryptography does **not** support Apple's deprecated OpenSSL distribution.
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500240
241To build cryptography and dynamically link it:
Ayrx1ced5b82014-04-08 19:41:26 +0800242
243`Homebrew`_
skeuomorfbc26efb2014-01-29 08:31:47 +0200244
245.. code-block:: console
246
Paul Kehrer524e7452017-03-09 19:18:24 -0400247 $ brew install openssl@1.1
248 $ env LDFLAGS="-L$(brew --prefix openssl@1.1)/lib" CFLAGS="-I$(brew --prefix openssl@1.1)/include" pip install cryptography
skeuomorfbc26efb2014-01-29 08:31:47 +0200249
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500250`MacPorts`_:
Kimmo Parviainen-Jalankoe01e0bf2014-03-19 18:57:09 +0200251
252.. code-block:: console
253
254 $ sudo port install openssl
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500255 $ env LDFLAGS="-L/opt/local/lib" CFLAGS="-I/opt/local/include" pip install cryptography
256
257You can also build cryptography statically:
258
259`Homebrew`_
260
261.. code-block:: console
262
Paul Kehrer524e7452017-03-09 19:18:24 -0400263 $ brew install openssl@1.1
Paul Kehreradeaacf2017-05-24 12:49:18 -0700264 $ env CRYPTOGRAPHY_SUPPRESS_LINK_FLAGS=1 LDFLAGS="$(brew --prefix openssl@1.1)/lib/libssl.a $(brew --prefix openssl@1.1)/lib/libcrypto.a" CFLAGS="-I$(brew --prefix openssl@1.1)/include" pip install cryptography
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500265
266`MacPorts`_:
267
268.. code-block:: console
269
270 $ sudo port install openssl
Paul Kehreradeaacf2017-05-24 12:49:18 -0700271 $ env CRYPTOGRAPHY_SUPPRESS_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 +0200272
Paul Kehrerd4ea53b2015-12-31 19:48:32 -0600273If you need to rebuild ``cryptography`` for any reason be sure to clear the
274local `wheel cache`_.
275
Alex Gaynoreb50a2c2014-05-02 09:38:33 -0700276Building cryptography with conda
277--------------------------------
278
Alex Gaynore51236d2016-11-06 10:13:35 -0500279Because of a bug in conda, attempting to install cryptography out of the box
David Reide162e262014-05-07 16:21:00 -0700280will result in an error. This can be resolved by setting the library path
281environment variable for your platform.
David Reide43861d2014-05-07 16:19:08 -0700282
Paul Kehrer524e7452017-03-09 19:18:24 -0400283On macOS:
Alex Gaynord8fc2572014-05-02 10:33:36 -0700284
285.. code-block:: console
286
287 $ env DYLD_LIBRARY_PATH="$HOME/anaconda/lib" pip install cryptography
288
David Reid18563e62014-05-07 16:20:09 -0700289and on Linux:
David Reide43861d2014-05-07 16:19:08 -0700290
291.. code-block:: console
292
293 $ env LD_LIBRARY_PATH="$HOME/anaconda/lib" pip install cryptography
294
Alex Gaynord8fc2572014-05-02 10:33:36 -0700295You will need to set this variable every time you start Python. For more
Alex Gaynorf65cba22014-05-02 10:40:57 -0700296information, consult `Greg Wilson's blog post`_ on the subject.
Alex Gaynoreb50a2c2014-05-02 09:38:33 -0700297
298
Alex Gaynor5ad6df92017-02-18 12:52:50 -0500299.. _`Homebrew`: https://brew.sh
Alex Gaynor3197ab52015-10-02 06:33:11 -0700300.. _`MacPorts`: https://www.macports.org
Paul Kehrer5a284e62017-05-29 17:09:23 -0500301.. _`openssl-release`: https://ci.cryptography.io/job/cryptography-support-jobs/job/openssl-release-1.1/
Alex Gaynor6422d832016-03-06 21:40:57 -0500302.. _`Greg Wilson's blog post`: https://software-carpentry.org/blog/2014/04/mr-biczo-was-right.html
Cory Benfieldba8f6382015-10-07 15:07:47 +0100303.. _virtualenv: https://virtualenv.pypa.io/en/latest/
Alex Gaynor769d5c62016-11-06 04:30:36 -0500304.. _openssl.org: https://www.openssl.org/source/
Paul Kehrerd4ea53b2015-12-31 19:48:32 -0600305.. _`wheel cache`: https://pip.pypa.io/en/stable/reference/pip_install/#caching