blob: 70668656d0a8bf89c5e660511f1baec2e2eb23b8 [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 Kehrere3a2fb22017-06-26 15:08:33 -100013Currently we test ``cryptography`` on Python 2.6, 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 Kehrer56b360a2015-12-31 19:59:25 -060024.. warning::
Alex Gaynordd567cb2017-09-30 21:22:07 -040025 Python 2.6 is no longer supported by the Python core team. The next release
26 of ``cryptography`` will drop support for Python 2.6.
Paul Kehrer56b360a2015-12-31 19:59:25 -060027
Paul Kehrerfb8dcdb2014-04-20 19:25:18 -050028We test compiling with ``clang`` as well as ``gcc`` and use the following
29OpenSSL releases:
30
Paul Kehrerfb8dcdb2014-04-20 19:25:18 -050031* ``OpenSSL 1.0.1``
Paul Kehrere683dee2014-08-09 08:15:23 -100032* ``OpenSSL 1.0.1e-fips`` (``RHEL/CentOS 7``)
Paul Kehrerda742982015-10-01 21:10:26 -050033* ``OpenSSL 1.0.1f``
Alex Gaynora5094962017-07-03 18:00:52 -040034* ``OpenSSL 1.0.1j-freebsd``
Paul Kehrerda742982015-10-01 21:10:26 -050035* ``OpenSSL 1.0.2-latest``
Alex Gaynor7a158272016-12-18 16:49:47 -050036* ``OpenSSL 1.1.0-latest``
Paul Kehrerfb8dcdb2014-04-20 19:25:18 -050037
Nick Badger63bbf182016-09-03 10:10:36 -070038Building cryptography on Windows
39--------------------------------
Alex Gaynor84d5c6b2014-02-02 10:12:34 -080040
Paul Kehrer156360a2014-06-30 12:14:01 -060041The wheel package on Windows is a statically linked build (as of 0.5) so all
Nick Badger63bbf182016-09-03 10:10:36 -070042dependencies are included. To install ``cryptography``, you will typically
43just run
Paul Kehrer156360a2014-06-30 12:14:01 -060044
45.. code-block:: console
46
47 $ pip install cryptography
48
49If you prefer to compile it yourself you'll need to have OpenSSL installed.
Paul Kehrer6608b7e2015-07-24 21:52:17 +010050You can compile OpenSSL yourself as well or use the binaries we build for our
Paul Kehrer937aa472015-10-11 12:09:27 -050051release infrastructure (`openssl-release`_). Be sure to download the proper
52version for your architecture and Python (2010 works for Python 2.6, 2.7, 3.3,
Paul Kehrerf19fef12017-02-09 13:53:44 +080053and 3.4 while 2015 is required for 3.5 and above). Wherever you place your copy
Paul Kehrer6608b7e2015-07-24 21:52:17 +010054of OpenSSL you'll need to set the ``LIB`` and ``INCLUDE`` environment variables
55to include the proper locations. For example:
skeuomorfbc26efb2014-01-29 08:31:47 +020056
skeuomorfb0293bf2014-01-29 21:41:02 +020057.. code-block:: console
58
59 C:\> \path\to\vcvarsall.bat x86_amd64
Paul Kehrer6608b7e2015-07-24 21:52:17 +010060 C:\> set LIB=C:\OpenSSL-win64\lib;%LIB%
61 C:\> set INCLUDE=C:\OpenSSL-win64\include;%INCLUDE%
Paul Kehrer2a39f7f2014-07-02 22:56:01 -050062 C:\> pip install cryptography
63
Paul Kehrerf19fef12017-02-09 13:53:44 +080064As of OpenSSL 1.1.0 the library names have changed from ``libeay32`` and
65``ssleay32`` to ``libcrypto`` and ``libssl`` (matching their names on all other
Paul Kehreradeaacf2017-05-24 12:49:18 -070066platforms). ``cryptography`` links against the new 1.1.0 names by default. If
67you need to compile ``cryptography`` against an older version then you **must**
68set ``CRYPTOGRAPHY_WINDOWS_LINK_LEGACY_OPENSSL`` or else installation will fail.
Paul Kehrerf19fef12017-02-09 13:53:44 +080069
Paul Kehrerd4ea53b2015-12-31 19:48:32 -060070If you need to rebuild ``cryptography`` for any reason be sure to clear the
71local `wheel cache`_.
skeuomorfbc26efb2014-01-29 08:31:47 +020072
Cory Benfield6d447282015-10-07 14:50:50 +010073.. _build-on-linux:
74
Chris Glass2e15c7f2014-02-13 19:10:10 +010075Building cryptography on Linux
76------------------------------
Chris Glass87c4edb2014-02-13 09:34:21 +010077
Paul Kehrer1eeaabb2017-07-01 17:34:36 -050078``cryptography`` ships a ``manylinux1`` wheel (as of 2.0) so all dependencies
79are included. For users on pip 8.1 or above running on a ``manylinux1``
80compatible distribution (almost everything except Alpine) all you should
81need to do is:
Chris Glass87c4edb2014-02-13 09:34:21 +010082
83.. code-block:: console
84
Paul Kehrer1eeaabb2017-07-01 17:34:36 -050085 $ pip install cryptography
Chris Glass87c4edb2014-02-13 09:34:21 +010086
Paul Kehrer1eeaabb2017-07-01 17:34:36 -050087If you are on Alpine or just want to compile it yourself then
88``cryptography`` requires a compiler, headers for Python (if you're not
89using ``pypy``), and headers for the OpenSSL and ``libffi`` libraries
90available on your system.
91
92Alpine
93~~~~~~
94
95Replace ``python3-dev`` with ``python-dev`` if you're using Python 2.
96
97.. code-block:: console
98
99 $ sudo apk add gcc musl-dev python3-dev libffi-dev openssl-dev
100
101If you get an error with ``openssl-dev`` you may have to use ``libressl-dev``.
102
103Debian/Ubuntu
104~~~~~~~~~~~~~
105
106Replace ``python3-dev`` with ``python-dev`` if you're using Python 2.
107
108.. code-block:: console
109
110 $ sudo apt-get install build-essential libssl-dev libffi-dev python3-dev
111
112RHEL/CentOS
113~~~~~~~~~~~
Ayrxa674c6b2014-02-15 21:24:23 +0800114
115.. code-block:: console
116
Alex Gaynord58c6ad2017-07-14 08:04:18 -0400117 $ sudo yum install redhat-rpm-config gcc libffi-devel python-devel \
118 openssl-devel
Ayrxa674c6b2014-02-15 21:24:23 +0800119
Paul Kehrer1eeaabb2017-07-01 17:34:36 -0500120
121Building
122~~~~~~~~
123
124You should now be able to build and install cryptography. To avoid getting
125the pre-built wheel on ``manylinux1`` distributions you'll need to use
126``--no-binary``.
Chris Glass87c4edb2014-02-13 09:34:21 +0100127
128.. code-block:: console
129
Paul Kehrer1eeaabb2017-07-01 17:34:36 -0500130 $ pip install cryptography --no-binary cryptography
Chris Glass87c4edb2014-02-13 09:34:21 +0100131
Alex Gaynoreb50a2c2014-05-02 09:38:33 -0700132
Chris Glass2e15c7f2014-02-13 19:10:10 +0100133Using your own OpenSSL on Linux
134~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
skeuomorfbc26efb2014-01-29 08:31:47 +0200135
136Python links to OpenSSL for its own purposes and this can sometimes cause
137problems when you wish to use a different version of OpenSSL with cryptography.
138If you want to use cryptography with your own build of OpenSSL you will need to
139make sure that the build is configured correctly so that your version of
140OpenSSL doesn't conflict with Python's.
141
142The options you need to add allow the linker to identify every symbol correctly
143even when multiple versions of the library are linked into the same program. If
144you are using your distribution's source packages these will probably be
145patched in for you already, otherwise you'll need to use options something like
146this when configuring OpenSSL:
147
148.. code-block:: console
149
150 $ ./config -Wl,--version-script=openssl.ld -Wl,-Bsymbolic-functions -fPIC shared
151
152You'll also need to generate your own ``openssl.ld`` file. For example::
153
Alex Gaynor46c0c622017-03-22 22:56:26 -0400154 OPENSSL_1.1.0E_CUSTOM {
skeuomorfbc26efb2014-01-29 08:31:47 +0200155 global:
156 *;
157 };
158
159You should replace the version string on the first line as appropriate for your
160build.
161
Cory Benfield6d447282015-10-07 14:50:50 +0100162Static Wheels
163~~~~~~~~~~~~~
164
Paul Kehrerf92f2d42017-07-04 16:00:08 -0500165Cryptography ships statically-linked wheels for macOS, Windows, and Linux (via
166``manylinux1``). This allows compatible environments to use the most recent
167OpenSSL, regardless of what is shipped by default on those platforms. Some
168Linux distributions (most notably Alpine) are not ``manylinux1`` compatible so
169we cannot distribute wheels for them.
Cory Benfield6d447282015-10-07 14:50:50 +0100170
171However, you can build your own statically-linked wheels that will work on your
172own systems. This will allow you to continue to use relatively old Linux
173distributions (such as LTS releases), while making sure you have the most
174recent OpenSSL available to your Python programs.
175
176To do so, you should find yourself a machine that is as similar as possible to
177your target environment (e.g. your production environment): for example, spin
178up a new cloud server running your target Linux distribution. On this machine,
179install the Cryptography dependencies as mentioned in :ref:`build-on-linux`.
180Please also make sure you have `virtualenv`_ installed: this should be
181available from your system package manager.
182
Cory Benfield80781842015-10-07 15:07:57 +0100183Then, paste the following into a shell script. You'll need to populate the
184``OPENSSL_VERSION`` variable. To do that, visit `openssl.org`_ and find the
185latest non-FIPS release version number, then set the string appropriately. For
Alex Gaynor46c0c622017-03-22 22:56:26 -0400186example, for OpenSSL 1.0.2k, use ``OPENSSL_VERSION="1.0.2k"``.
Cory Benfield6d447282015-10-07 14:50:50 +0100187
188When this shell script is complete, you'll find a collection of wheel files in
189a directory called ``wheelhouse``. These wheels can be installed by a
190sufficiently-recent version of ``pip``. The Cryptography wheel in this
191directory contains a statically-linked OpenSSL binding, which ensures that you
192have access to the most-recent OpenSSL releases without corrupting your system
193dependencies.
194
195.. code-block:: console
196
197 set -e
198
Cory Benfield80781842015-10-07 15:07:57 +0100199 OPENSSL_VERSION="VERSIONGOESHERE"
Cory Benfield6d447282015-10-07 14:50:50 +0100200 CWD=$(pwd)
201
202 virtualenv env
203 . env/bin/activate
204 pip install -U setuptools
205 pip install -U wheel pip
Matt Thomasa187c972016-10-03 17:48:31 -0400206 curl -O https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz
Cory Benfield6d447282015-10-07 14:50:50 +0100207 tar xvf openssl-${OPENSSL_VERSION}.tar.gz
208 cd openssl-${OPENSSL_VERSION}
Alex Gaynor46c0c622017-03-22 22:56:26 -0400209 ./config no-shared no-ssl2 no-ssl3 -fPIC --prefix=${CWD}/openssl
Cory Benfield6d447282015-10-07 14:50:50 +0100210 make && make install
211 cd ..
Cory Benfield09d1b472015-10-16 08:14:42 +0100212 CFLAGS="-I${CWD}/openssl/include" LDFLAGS="-L${CWD}/openssl/lib" pip wheel --no-use-wheel cryptography
Cory Benfield6d447282015-10-07 14:50:50 +0100213
Paul Kehrer524e7452017-03-09 19:18:24 -0400214Building cryptography on macOS
215------------------------------
Paul Kehrer451c8df2015-07-04 11:03:27 -0500216
Paul Kehrera17d5902016-03-20 22:29:17 -0400217.. note::
218
219 If installation gives a ``fatal error: 'openssl/aes.h' file not found``
220 see the :doc:`FAQ </faq>` for information about how to fix this issue.
221
Paul Kehrer524e7452017-03-09 19:18:24 -0400222The wheel package on macOS is a statically linked build (as of 1.0.1) so for
Paul Kehrera17d5902016-03-20 22:29:17 -0400223users with pip 8 or above you only need one step:
Paul Kehrer451c8df2015-07-04 11:03:27 -0500224
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500225.. code-block:: console
skeuomorfbc26efb2014-01-29 08:31:47 +0200226
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500227 $ pip install cryptography
228
Paul Kehrer524e7452017-03-09 19:18:24 -0400229If you want to build cryptography yourself or are on an older macOS version,
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500230cryptography requires the presence of a C compiler, development headers, and
Paul Kehrer524e7452017-03-09 19:18:24 -0400231the proper libraries. On macOS much of this is provided by Apple's Xcode
232development tools. To install the Xcode command line tools (on macOS 10.9+)
Paul Kehrerb29f4642015-12-31 23:27:25 -0600233open a terminal window and run:
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500234
235.. code-block:: console
236
237 $ xcode-select --install
238
239This will install a compiler (clang) along with (most of) the required
240development headers.
241
242You'll also need OpenSSL, which you can obtain from `Homebrew`_ or `MacPorts`_.
Paul Kehrer355174a2015-12-22 09:47:26 -0600243Cryptography does **not** support Apple's deprecated OpenSSL distribution.
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500244
245To build cryptography and dynamically link it:
Ayrx1ced5b82014-04-08 19:41:26 +0800246
247`Homebrew`_
skeuomorfbc26efb2014-01-29 08:31:47 +0200248
249.. code-block:: console
250
Paul Kehrer524e7452017-03-09 19:18:24 -0400251 $ brew install openssl@1.1
252 $ 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 +0200253
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500254`MacPorts`_:
Kimmo Parviainen-Jalankoe01e0bf2014-03-19 18:57:09 +0200255
256.. code-block:: console
257
258 $ sudo port install openssl
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500259 $ env LDFLAGS="-L/opt/local/lib" CFLAGS="-I/opt/local/include" pip install cryptography
260
261You can also build cryptography statically:
262
263`Homebrew`_
264
265.. code-block:: console
266
Paul Kehrer524e7452017-03-09 19:18:24 -0400267 $ brew install openssl@1.1
Paul Kehreradeaacf2017-05-24 12:49:18 -0700268 $ 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 -0500269
270`MacPorts`_:
271
272.. code-block:: console
273
274 $ sudo port install openssl
Paul Kehreradeaacf2017-05-24 12:49:18 -0700275 $ 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 +0200276
Paul Kehrerd4ea53b2015-12-31 19:48:32 -0600277If you need to rebuild ``cryptography`` for any reason be sure to clear the
278local `wheel cache`_.
279
Alex Gaynoreb50a2c2014-05-02 09:38:33 -0700280Building cryptography with conda
281--------------------------------
282
Alex Gaynore51236d2016-11-06 10:13:35 -0500283Because of a bug in conda, attempting to install cryptography out of the box
David Reide162e262014-05-07 16:21:00 -0700284will result in an error. This can be resolved by setting the library path
285environment variable for your platform.
David Reide43861d2014-05-07 16:19:08 -0700286
Paul Kehrer524e7452017-03-09 19:18:24 -0400287On macOS:
Alex Gaynord8fc2572014-05-02 10:33:36 -0700288
289.. code-block:: console
290
291 $ env DYLD_LIBRARY_PATH="$HOME/anaconda/lib" pip install cryptography
292
David Reid18563e62014-05-07 16:20:09 -0700293and on Linux:
David Reide43861d2014-05-07 16:19:08 -0700294
295.. code-block:: console
296
297 $ env LD_LIBRARY_PATH="$HOME/anaconda/lib" pip install cryptography
298
Alex Gaynord8fc2572014-05-02 10:33:36 -0700299You will need to set this variable every time you start Python. For more
Alex Gaynorf65cba22014-05-02 10:40:57 -0700300information, consult `Greg Wilson's blog post`_ on the subject.
Alex Gaynoreb50a2c2014-05-02 09:38:33 -0700301
302
Alex Gaynor5ad6df92017-02-18 12:52:50 -0500303.. _`Homebrew`: https://brew.sh
Alex Gaynor3197ab52015-10-02 06:33:11 -0700304.. _`MacPorts`: https://www.macports.org
Paul Kehrer5a284e62017-05-29 17:09:23 -0500305.. _`openssl-release`: https://ci.cryptography.io/job/cryptography-support-jobs/job/openssl-release-1.1/
Alex Gaynor6422d832016-03-06 21:40:57 -0500306.. _`Greg Wilson's blog post`: https://software-carpentry.org/blog/2014/04/mr-biczo-was-right.html
Cory Benfieldba8f6382015-10-07 15:07:47 +0100307.. _virtualenv: https://virtualenv.pypa.io/en/latest/
Alex Gaynor769d5c62016-11-06 04:30:36 -0500308.. _openssl.org: https://www.openssl.org/source/
Paul Kehrerd4ea53b2015-12-31 19:48:32 -0600309.. _`wheel cache`: https://pip.pypa.io/en/stable/reference/pip_install/#caching