blob: d665dbc59dd827d152a5033d4d0f0c1078dee6dc [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 Kehrer4ee1cb92018-06-27 20:07:14 -070013Currently we test ``cryptography`` on Python 2.7, 3.4+, 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
Alex Gaynore6859232017-09-26 20:03:53 -040017* macOS 10.12 Sierra, 10.11 El Capitan
Paul Kehrer6a10b292017-05-27 19:32:26 -050018* x86-64 Ubuntu 14.04, 16.04, and rolling
19* x86-64 Debian Wheezy (7.x), Jessie (8.x), Stretch (9.x), and Sid (unstable)
Paul Kehrer1eeaabb2017-07-01 17:34:36 -050020* x86-64 Alpine (latest)
Paul Kehrerda742982015-10-01 21:10:26 -050021* 32-bit and 64-bit Python on 64-bit Windows Server 2012
Alex Stapletonb4684172014-03-15 18:02:13 +000022
Paul Kehrerfb8dcdb2014-04-20 19:25:18 -050023We test compiling with ``clang`` as well as ``gcc`` and use the following
24OpenSSL releases:
25
Paul Kehrerfb8dcdb2014-04-20 19:25:18 -050026* ``OpenSSL 1.0.1``
Paul Kehrere683dee2014-08-09 08:15:23 -100027* ``OpenSSL 1.0.1e-fips`` (``RHEL/CentOS 7``)
Paul Kehrerda742982015-10-01 21:10:26 -050028* ``OpenSSL 1.0.1f``
29* ``OpenSSL 1.0.2-latest``
Alex Gaynor7a158272016-12-18 16:49:47 -050030* ``OpenSSL 1.1.0-latest``
Paul Kehrer71279722018-08-29 21:29:37 -040031* ``OpenSSL 1.1.1-latest``
Paul Kehrerfb8dcdb2014-04-20 19:25:18 -050032
Nick Badger63bbf182016-09-03 10:10:36 -070033Building cryptography on Windows
34--------------------------------
Alex Gaynor84d5c6b2014-02-02 10:12:34 -080035
Paul Kehrer156360a2014-06-30 12:14:01 -060036The wheel package on Windows is a statically linked build (as of 0.5) so all
Nick Badger63bbf182016-09-03 10:10:36 -070037dependencies are included. To install ``cryptography``, you will typically
38just run
Paul Kehrer156360a2014-06-30 12:14:01 -060039
40.. code-block:: console
41
42 $ pip install cryptography
43
44If you prefer to compile it yourself you'll need to have OpenSSL installed.
Paul Kehrer6608b7e2015-07-24 21:52:17 +010045You can compile OpenSSL yourself as well or use the binaries we build for our
Paul Kehrer937aa472015-10-11 12:09:27 -050046release infrastructure (`openssl-release`_). Be sure to download the proper
Paul Kehrer4cf6e782017-10-12 06:06:01 +080047version for your architecture and Python (2010 works for Python 2.7, 3.3,
Paul Kehrerf19fef12017-02-09 13:53:44 +080048and 3.4 while 2015 is required for 3.5 and above). Wherever you place your copy
Paul Kehrer6608b7e2015-07-24 21:52:17 +010049of OpenSSL you'll need to set the ``LIB`` and ``INCLUDE`` environment variables
50to include the proper locations. For example:
skeuomorfbc26efb2014-01-29 08:31:47 +020051
skeuomorfb0293bf2014-01-29 21:41:02 +020052.. code-block:: console
53
54 C:\> \path\to\vcvarsall.bat x86_amd64
Paul Kehrer6608b7e2015-07-24 21:52:17 +010055 C:\> set LIB=C:\OpenSSL-win64\lib;%LIB%
56 C:\> set INCLUDE=C:\OpenSSL-win64\include;%INCLUDE%
Paul Kehrer2a39f7f2014-07-02 22:56:01 -050057 C:\> pip install cryptography
58
Paul Kehrerf19fef12017-02-09 13:53:44 +080059As of OpenSSL 1.1.0 the library names have changed from ``libeay32`` and
60``ssleay32`` to ``libcrypto`` and ``libssl`` (matching their names on all other
Paul Kehreradeaacf2017-05-24 12:49:18 -070061platforms). ``cryptography`` links against the new 1.1.0 names by default. If
62you need to compile ``cryptography`` against an older version then you **must**
63set ``CRYPTOGRAPHY_WINDOWS_LINK_LEGACY_OPENSSL`` or else installation will fail.
Paul Kehrerf19fef12017-02-09 13:53:44 +080064
Paul Kehrerd4ea53b2015-12-31 19:48:32 -060065If you need to rebuild ``cryptography`` for any reason be sure to clear the
66local `wheel cache`_.
skeuomorfbc26efb2014-01-29 08:31:47 +020067
Cory Benfield6d447282015-10-07 14:50:50 +010068.. _build-on-linux:
69
Chris Glass2e15c7f2014-02-13 19:10:10 +010070Building cryptography on Linux
71------------------------------
Chris Glass87c4edb2014-02-13 09:34:21 +010072
Paul Kehrer1eeaabb2017-07-01 17:34:36 -050073``cryptography`` ships a ``manylinux1`` wheel (as of 2.0) so all dependencies
74are included. For users on pip 8.1 or above running on a ``manylinux1``
75compatible distribution (almost everything except Alpine) all you should
76need to do is:
Chris Glass87c4edb2014-02-13 09:34:21 +010077
78.. code-block:: console
79
Paul Kehrer1eeaabb2017-07-01 17:34:36 -050080 $ pip install cryptography
Chris Glass87c4edb2014-02-13 09:34:21 +010081
Paul Kehrer1eeaabb2017-07-01 17:34:36 -050082If you are on Alpine or just want to compile it yourself then
83``cryptography`` requires a compiler, headers for Python (if you're not
84using ``pypy``), and headers for the OpenSSL and ``libffi`` libraries
85available on your system.
86
87Alpine
88~~~~~~
89
90Replace ``python3-dev`` with ``python-dev`` if you're using Python 2.
91
92.. code-block:: console
93
94 $ sudo apk add gcc musl-dev python3-dev libffi-dev openssl-dev
95
96If you get an error with ``openssl-dev`` you may have to use ``libressl-dev``.
97
98Debian/Ubuntu
99~~~~~~~~~~~~~
100
101Replace ``python3-dev`` with ``python-dev`` if you're using Python 2.
102
103.. code-block:: console
104
105 $ sudo apt-get install build-essential libssl-dev libffi-dev python3-dev
106
107RHEL/CentOS
108~~~~~~~~~~~
Ayrxa674c6b2014-02-15 21:24:23 +0800109
110.. code-block:: console
111
Alex Gaynord58c6ad2017-07-14 08:04:18 -0400112 $ sudo yum install redhat-rpm-config gcc libffi-devel python-devel \
113 openssl-devel
Ayrxa674c6b2014-02-15 21:24:23 +0800114
Paul Kehrer1eeaabb2017-07-01 17:34:36 -0500115
116Building
117~~~~~~~~
118
119You should now be able to build and install cryptography. To avoid getting
120the pre-built wheel on ``manylinux1`` distributions you'll need to use
121``--no-binary``.
Chris Glass87c4edb2014-02-13 09:34:21 +0100122
123.. code-block:: console
124
Paul Kehrer1eeaabb2017-07-01 17:34:36 -0500125 $ pip install cryptography --no-binary cryptography
Chris Glass87c4edb2014-02-13 09:34:21 +0100126
Alex Gaynoreb50a2c2014-05-02 09:38:33 -0700127
Chris Glass2e15c7f2014-02-13 19:10:10 +0100128Using your own OpenSSL on Linux
129~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
skeuomorfbc26efb2014-01-29 08:31:47 +0200130
131Python links to OpenSSL for its own purposes and this can sometimes cause
132problems when you wish to use a different version of OpenSSL with cryptography.
133If you want to use cryptography with your own build of OpenSSL you will need to
134make sure that the build is configured correctly so that your version of
135OpenSSL doesn't conflict with Python's.
136
137The options you need to add allow the linker to identify every symbol correctly
138even when multiple versions of the library are linked into the same program. If
139you are using your distribution's source packages these will probably be
140patched in for you already, otherwise you'll need to use options something like
141this when configuring OpenSSL:
142
143.. code-block:: console
144
145 $ ./config -Wl,--version-script=openssl.ld -Wl,-Bsymbolic-functions -fPIC shared
146
147You'll also need to generate your own ``openssl.ld`` file. For example::
148
Alex Gaynor46c0c622017-03-22 22:56:26 -0400149 OPENSSL_1.1.0E_CUSTOM {
skeuomorfbc26efb2014-01-29 08:31:47 +0200150 global:
151 *;
152 };
153
154You should replace the version string on the first line as appropriate for your
155build.
156
Cory Benfield6d447282015-10-07 14:50:50 +0100157Static Wheels
158~~~~~~~~~~~~~
159
Paul Kehrerf92f2d42017-07-04 16:00:08 -0500160Cryptography ships statically-linked wheels for macOS, Windows, and Linux (via
161``manylinux1``). This allows compatible environments to use the most recent
162OpenSSL, regardless of what is shipped by default on those platforms. Some
163Linux distributions (most notably Alpine) are not ``manylinux1`` compatible so
164we cannot distribute wheels for them.
Cory Benfield6d447282015-10-07 14:50:50 +0100165
166However, you can build your own statically-linked wheels that will work on your
167own systems. This will allow you to continue to use relatively old Linux
168distributions (such as LTS releases), while making sure you have the most
169recent OpenSSL available to your Python programs.
170
171To do so, you should find yourself a machine that is as similar as possible to
172your target environment (e.g. your production environment): for example, spin
173up a new cloud server running your target Linux distribution. On this machine,
174install the Cryptography dependencies as mentioned in :ref:`build-on-linux`.
175Please also make sure you have `virtualenv`_ installed: this should be
176available from your system package manager.
177
Cory Benfield80781842015-10-07 15:07:57 +0100178Then, paste the following into a shell script. You'll need to populate the
179``OPENSSL_VERSION`` variable. To do that, visit `openssl.org`_ and find the
180latest non-FIPS release version number, then set the string appropriately. For
Alex Gaynor46c0c622017-03-22 22:56:26 -0400181example, for OpenSSL 1.0.2k, use ``OPENSSL_VERSION="1.0.2k"``.
Cory Benfield6d447282015-10-07 14:50:50 +0100182
183When this shell script is complete, you'll find a collection of wheel files in
184a directory called ``wheelhouse``. These wheels can be installed by a
185sufficiently-recent version of ``pip``. The Cryptography wheel in this
186directory contains a statically-linked OpenSSL binding, which ensures that you
187have access to the most-recent OpenSSL releases without corrupting your system
188dependencies.
189
190.. code-block:: console
191
192 set -e
193
Cory Benfield80781842015-10-07 15:07:57 +0100194 OPENSSL_VERSION="VERSIONGOESHERE"
Cory Benfield6d447282015-10-07 14:50:50 +0100195 CWD=$(pwd)
196
197 virtualenv env
198 . env/bin/activate
199 pip install -U setuptools
200 pip install -U wheel pip
Matt Thomasa187c972016-10-03 17:48:31 -0400201 curl -O https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz
Cory Benfield6d447282015-10-07 14:50:50 +0100202 tar xvf openssl-${OPENSSL_VERSION}.tar.gz
203 cd openssl-${OPENSSL_VERSION}
Alex Gaynor46c0c622017-03-22 22:56:26 -0400204 ./config no-shared no-ssl2 no-ssl3 -fPIC --prefix=${CWD}/openssl
Cory Benfield6d447282015-10-07 14:50:50 +0100205 make && make install
206 cd ..
Justin Holmesdd051822018-04-30 19:22:43 -0700207 CFLAGS="-I${CWD}/openssl/include" LDFLAGS="-L${CWD}/openssl/lib" pip wheel --no-binary :all: cryptography
Cory Benfield6d447282015-10-07 14:50:50 +0100208
Paul Kehrer524e7452017-03-09 19:18:24 -0400209Building cryptography on macOS
210------------------------------
Paul Kehrer451c8df2015-07-04 11:03:27 -0500211
Paul Kehrera17d5902016-03-20 22:29:17 -0400212.. note::
213
214 If installation gives a ``fatal error: 'openssl/aes.h' file not found``
215 see the :doc:`FAQ </faq>` for information about how to fix this issue.
216
Paul Kehrer524e7452017-03-09 19:18:24 -0400217The wheel package on macOS is a statically linked build (as of 1.0.1) so for
Paul Kehrera17d5902016-03-20 22:29:17 -0400218users with pip 8 or above you only need one step:
Paul Kehrer451c8df2015-07-04 11:03:27 -0500219
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500220.. code-block:: console
skeuomorfbc26efb2014-01-29 08:31:47 +0200221
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500222 $ pip install cryptography
223
Paul Kehrer524e7452017-03-09 19:18:24 -0400224If you want to build cryptography yourself or are on an older macOS version,
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500225cryptography requires the presence of a C compiler, development headers, and
Paul Kehrer524e7452017-03-09 19:18:24 -0400226the proper libraries. On macOS much of this is provided by Apple's Xcode
227development tools. To install the Xcode command line tools (on macOS 10.9+)
Paul Kehrerb29f4642015-12-31 23:27:25 -0600228open a terminal window and run:
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500229
230.. code-block:: console
231
232 $ xcode-select --install
233
234This will install a compiler (clang) along with (most of) the required
235development headers.
236
237You'll also need OpenSSL, which you can obtain from `Homebrew`_ or `MacPorts`_.
Paul Kehrer355174a2015-12-22 09:47:26 -0600238Cryptography does **not** support Apple's deprecated OpenSSL distribution.
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500239
240To build cryptography and dynamically link it:
Ayrx1ced5b82014-04-08 19:41:26 +0800241
242`Homebrew`_
skeuomorfbc26efb2014-01-29 08:31:47 +0200243
244.. code-block:: console
245
Paul Kehrer524e7452017-03-09 19:18:24 -0400246 $ brew install openssl@1.1
247 $ 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 +0200248
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500249`MacPorts`_:
Kimmo Parviainen-Jalankoe01e0bf2014-03-19 18:57:09 +0200250
251.. code-block:: console
252
253 $ sudo port install openssl
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500254 $ env LDFLAGS="-L/opt/local/lib" CFLAGS="-I/opt/local/include" pip install cryptography
255
256You can also build cryptography statically:
257
258`Homebrew`_
259
260.. code-block:: console
261
Paul Kehrer524e7452017-03-09 19:18:24 -0400262 $ brew install openssl@1.1
Paul Kehreradeaacf2017-05-24 12:49:18 -0700263 $ 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 -0500264
265`MacPorts`_:
266
267.. code-block:: console
268
269 $ sudo port install openssl
Paul Kehreradeaacf2017-05-24 12:49:18 -0700270 $ 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 +0200271
Paul Kehrerd4ea53b2015-12-31 19:48:32 -0600272If you need to rebuild ``cryptography`` for any reason be sure to clear the
273local `wheel cache`_.
274
Alex Gaynoreb50a2c2014-05-02 09:38:33 -0700275
Alex Gaynor5ad6df92017-02-18 12:52:50 -0500276.. _`Homebrew`: https://brew.sh
Alex Gaynor3197ab52015-10-02 06:33:11 -0700277.. _`MacPorts`: https://www.macports.org
Paul Kehrer5a284e62017-05-29 17:09:23 -0500278.. _`openssl-release`: https://ci.cryptography.io/job/cryptography-support-jobs/job/openssl-release-1.1/
Cory Benfieldba8f6382015-10-07 15:07:47 +0100279.. _virtualenv: https://virtualenv.pypa.io/en/latest/
Alex Gaynor769d5c62016-11-06 04:30:36 -0500280.. _openssl.org: https://www.openssl.org/source/
Paul Kehrerd4ea53b2015-12-31 19:48:32 -0600281.. _`wheel cache`: https://pip.pypa.io/en/stable/reference/pip_install/#caching