blob: 0fa986a11d4fffed2aa0b3e0db63609f63ae2497 [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 Gaynor2240ba22017-05-20 13:23:15 -070018* macOS 10.12 Sierra, 10.11 El Capitan, 10.10 Yosemite, 10.9 Mavericks
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 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 Kehrer56b360a2015-12-31 19:59:25 -060023.. warning::
24 Python 2.6 is no longer supported by the Python core team. A future version
25 of cryptography will drop support for this version.
26
Paul Kehrerfb8dcdb2014-04-20 19:25:18 -050027We test compiling with ``clang`` as well as ``gcc`` and use the following
28OpenSSL releases:
29
Paul Kehrerfb8dcdb2014-04-20 19:25:18 -050030* ``OpenSSL 1.0.1``
Paul Kehrere683dee2014-08-09 08:15:23 -100031* ``OpenSSL 1.0.1e-fips`` (``RHEL/CentOS 7``)
Paul Kehrer96a08272015-02-21 18:37:38 -060032* ``OpenSSL 1.0.1j-freebsd``
Paul Kehrerda742982015-10-01 21:10:26 -050033* ``OpenSSL 1.0.1f``
34* ``OpenSSL 1.0.2-latest``
Alex Gaynor7a158272016-12-18 16:49:47 -050035* ``OpenSSL 1.1.0-latest``
Paul Kehrerfb8dcdb2014-04-20 19:25:18 -050036
Nick Badger63bbf182016-09-03 10:10:36 -070037Building cryptography on 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
Nick Badger63bbf182016-09-03 10:10:36 -070041dependencies are included. To install ``cryptography``, you will typically
42just run
Paul Kehrer156360a2014-06-30 12:14:01 -060043
44.. code-block:: console
45
46 $ pip install cryptography
47
48If you prefer to compile it yourself you'll need to have OpenSSL installed.
Paul Kehrer6608b7e2015-07-24 21:52:17 +010049You can compile OpenSSL yourself as well or use the binaries we build for our
Paul Kehrer937aa472015-10-11 12:09:27 -050050release infrastructure (`openssl-release`_). Be sure to download the proper
51version for your architecture and Python (2010 works for Python 2.6, 2.7, 3.3,
Paul Kehrerf19fef12017-02-09 13:53:44 +080052and 3.4 while 2015 is required for 3.5 and above). Wherever you place your copy
Paul Kehrer6608b7e2015-07-24 21:52:17 +010053of OpenSSL you'll need to set the ``LIB`` and ``INCLUDE`` environment variables
54to include the proper locations. For example:
skeuomorfbc26efb2014-01-29 08:31:47 +020055
skeuomorfb0293bf2014-01-29 21:41:02 +020056.. code-block:: console
57
58 C:\> \path\to\vcvarsall.bat x86_amd64
Paul Kehrer6608b7e2015-07-24 21:52:17 +010059 C:\> set LIB=C:\OpenSSL-win64\lib;%LIB%
60 C:\> set INCLUDE=C:\OpenSSL-win64\include;%INCLUDE%
Paul Kehrer2a39f7f2014-07-02 22:56:01 -050061 C:\> pip install cryptography
62
Paul Kehrerf19fef12017-02-09 13:53:44 +080063As of OpenSSL 1.1.0 the library names have changed from ``libeay32`` and
64``ssleay32`` to ``libcrypto`` and ``libssl`` (matching their names on all other
Paul Kehreradeaacf2017-05-24 12:49:18 -070065platforms). ``cryptography`` links against the new 1.1.0 names by default. If
66you need to compile ``cryptography`` against an older version then you **must**
67set ``CRYPTOGRAPHY_WINDOWS_LINK_LEGACY_OPENSSL`` or else installation will fail.
Paul Kehrerf19fef12017-02-09 13:53:44 +080068
Paul Kehrerd4ea53b2015-12-31 19:48:32 -060069If you need to rebuild ``cryptography`` for any reason be sure to clear the
70local `wheel cache`_.
skeuomorfbc26efb2014-01-29 08:31:47 +020071
Cory Benfield6d447282015-10-07 14:50:50 +010072.. _build-on-linux:
73
Chris Glass2e15c7f2014-02-13 19:10:10 +010074Building cryptography on Linux
75------------------------------
Chris Glass87c4edb2014-02-13 09:34:21 +010076
Chris Glass2e15c7f2014-02-13 19:10:10 +010077``cryptography`` should build very easily on Linux provided you have a C
Alex Gaynor49923842014-02-13 10:32:56 -080078compiler, headers for Python (if you're not using ``pypy``), and headers for
79the OpenSSL and ``libffi`` libraries available on your system.
Chris Glass87c4edb2014-02-13 09:34:21 +010080
Ayrxd9702f92014-02-15 23:57:13 +080081For Debian and Ubuntu, the following command will ensure that the required
Alex Gaynord0c69832017-01-21 09:20:54 -050082dependencies are installed (replace ``python-dev`` with ``python3-dev`` if
83you're using Python 3):
Chris Glass87c4edb2014-02-13 09:34:21 +010084
85.. code-block:: console
86
Alex Gaynor49923842014-02-13 10:32:56 -080087 $ sudo apt-get install build-essential libssl-dev libffi-dev python-dev
Chris Glass87c4edb2014-02-13 09:34:21 +010088
Ayrxd9702f92014-02-15 23:57:13 +080089For Fedora and RHEL-derivatives, the following command will ensure that the
Alex Gaynord0c69832017-01-21 09:20:54 -050090required dependencies are installed (replace ``python-devel`` with
91``python3-devel`` if you're using Python 3):
Ayrxa674c6b2014-02-15 21:24:23 +080092
93.. code-block:: console
94
95 $ sudo yum install gcc libffi-devel python-devel openssl-devel
96
Chris Glass87c4edb2014-02-13 09:34:21 +010097You should now be able to build and install cryptography with the usual
98
99.. code-block:: console
100
Alex Gaynor49923842014-02-13 10:32:56 -0800101 $ pip install cryptography
Chris Glass87c4edb2014-02-13 09:34:21 +0100102
Alex Gaynoreb50a2c2014-05-02 09:38:33 -0700103
Chris Glass2e15c7f2014-02-13 19:10:10 +0100104Using your own OpenSSL on Linux
105~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
skeuomorfbc26efb2014-01-29 08:31:47 +0200106
107Python links to OpenSSL for its own purposes and this can sometimes cause
108problems when you wish to use a different version of OpenSSL with cryptography.
109If you want to use cryptography with your own build of OpenSSL you will need to
110make sure that the build is configured correctly so that your version of
111OpenSSL doesn't conflict with Python's.
112
113The options you need to add allow the linker to identify every symbol correctly
114even when multiple versions of the library are linked into the same program. If
115you are using your distribution's source packages these will probably be
116patched in for you already, otherwise you'll need to use options something like
117this when configuring OpenSSL:
118
119.. code-block:: console
120
121 $ ./config -Wl,--version-script=openssl.ld -Wl,-Bsymbolic-functions -fPIC shared
122
123You'll also need to generate your own ``openssl.ld`` file. For example::
124
Alex Gaynor46c0c622017-03-22 22:56:26 -0400125 OPENSSL_1.1.0E_CUSTOM {
skeuomorfbc26efb2014-01-29 08:31:47 +0200126 global:
127 *;
128 };
129
130You should replace the version string on the first line as appropriate for your
131build.
132
Cory Benfield6d447282015-10-07 14:50:50 +0100133Static Wheels
134~~~~~~~~~~~~~
135
Paul Kehrer524e7452017-03-09 19:18:24 -0400136Cryptography ships statically-linked wheels for macOS and Windows, ensuring
137that these platforms can always use the most-recent OpenSSL, regardless of what
138is shipped by default on those platforms. As a result of various difficulties
Cory Benfield6d447282015-10-07 14:50:50 +0100139around Linux binary linking, Cryptography cannot do the same on Linux.
140
141However, you can build your own statically-linked wheels that will work on your
142own systems. This will allow you to continue to use relatively old Linux
143distributions (such as LTS releases), while making sure you have the most
144recent OpenSSL available to your Python programs.
145
146To do so, you should find yourself a machine that is as similar as possible to
147your target environment (e.g. your production environment): for example, spin
148up a new cloud server running your target Linux distribution. On this machine,
149install the Cryptography dependencies as mentioned in :ref:`build-on-linux`.
150Please also make sure you have `virtualenv`_ installed: this should be
151available from your system package manager.
152
Cory Benfield80781842015-10-07 15:07:57 +0100153Then, paste the following into a shell script. You'll need to populate the
154``OPENSSL_VERSION`` variable. To do that, visit `openssl.org`_ and find the
155latest non-FIPS release version number, then set the string appropriately. For
Alex Gaynor46c0c622017-03-22 22:56:26 -0400156example, for OpenSSL 1.0.2k, use ``OPENSSL_VERSION="1.0.2k"``.
Cory Benfield6d447282015-10-07 14:50:50 +0100157
158When this shell script is complete, you'll find a collection of wheel files in
159a directory called ``wheelhouse``. These wheels can be installed by a
160sufficiently-recent version of ``pip``. The Cryptography wheel in this
161directory contains a statically-linked OpenSSL binding, which ensures that you
162have access to the most-recent OpenSSL releases without corrupting your system
163dependencies.
164
165.. code-block:: console
166
167 set -e
168
Cory Benfield80781842015-10-07 15:07:57 +0100169 OPENSSL_VERSION="VERSIONGOESHERE"
Cory Benfield6d447282015-10-07 14:50:50 +0100170 CWD=$(pwd)
171
172 virtualenv env
173 . env/bin/activate
174 pip install -U setuptools
175 pip install -U wheel pip
Matt Thomasa187c972016-10-03 17:48:31 -0400176 curl -O https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz
Cory Benfield6d447282015-10-07 14:50:50 +0100177 tar xvf openssl-${OPENSSL_VERSION}.tar.gz
178 cd openssl-${OPENSSL_VERSION}
Alex Gaynor46c0c622017-03-22 22:56:26 -0400179 ./config no-shared no-ssl2 no-ssl3 -fPIC --prefix=${CWD}/openssl
Cory Benfield6d447282015-10-07 14:50:50 +0100180 make && make install
181 cd ..
Cory Benfield09d1b472015-10-16 08:14:42 +0100182 CFLAGS="-I${CWD}/openssl/include" LDFLAGS="-L${CWD}/openssl/lib" pip wheel --no-use-wheel cryptography
Cory Benfield6d447282015-10-07 14:50:50 +0100183
Paul Kehrer524e7452017-03-09 19:18:24 -0400184Building cryptography on macOS
185------------------------------
Paul Kehrer451c8df2015-07-04 11:03:27 -0500186
Paul Kehrera17d5902016-03-20 22:29:17 -0400187.. note::
188
189 If installation gives a ``fatal error: 'openssl/aes.h' file not found``
190 see the :doc:`FAQ </faq>` for information about how to fix this issue.
191
Paul Kehrer524e7452017-03-09 19:18:24 -0400192The wheel package on macOS is a statically linked build (as of 1.0.1) so for
Paul Kehrera17d5902016-03-20 22:29:17 -0400193users with pip 8 or above you only need one step:
Paul Kehrer451c8df2015-07-04 11:03:27 -0500194
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500195.. code-block:: console
skeuomorfbc26efb2014-01-29 08:31:47 +0200196
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500197 $ pip install cryptography
198
Paul Kehrer524e7452017-03-09 19:18:24 -0400199If you want to build cryptography yourself or are on an older macOS version,
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500200cryptography requires the presence of a C compiler, development headers, and
Paul Kehrer524e7452017-03-09 19:18:24 -0400201the proper libraries. On macOS much of this is provided by Apple's Xcode
202development tools. To install the Xcode command line tools (on macOS 10.9+)
Paul Kehrerb29f4642015-12-31 23:27:25 -0600203open a terminal window and run:
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500204
205.. code-block:: console
206
207 $ xcode-select --install
208
209This will install a compiler (clang) along with (most of) the required
210development headers.
211
212You'll also need OpenSSL, which you can obtain from `Homebrew`_ or `MacPorts`_.
Paul Kehrer355174a2015-12-22 09:47:26 -0600213Cryptography does **not** support Apple's deprecated OpenSSL distribution.
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500214
215To build cryptography and dynamically link it:
Ayrx1ced5b82014-04-08 19:41:26 +0800216
217`Homebrew`_
skeuomorfbc26efb2014-01-29 08:31:47 +0200218
219.. code-block:: console
220
Paul Kehrer524e7452017-03-09 19:18:24 -0400221 $ brew install openssl@1.1
222 $ 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 +0200223
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500224`MacPorts`_:
Kimmo Parviainen-Jalankoe01e0bf2014-03-19 18:57:09 +0200225
226.. code-block:: console
227
228 $ sudo port install openssl
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500229 $ env LDFLAGS="-L/opt/local/lib" CFLAGS="-I/opt/local/include" pip install cryptography
230
231You can also build cryptography statically:
232
233`Homebrew`_
234
235.. code-block:: console
236
Paul Kehrer524e7452017-03-09 19:18:24 -0400237 $ brew install openssl@1.1
Paul Kehreradeaacf2017-05-24 12:49:18 -0700238 $ 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 -0500239
240`MacPorts`_:
241
242.. code-block:: console
243
244 $ sudo port install openssl
Paul Kehreradeaacf2017-05-24 12:49:18 -0700245 $ 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 +0200246
Paul Kehrerd4ea53b2015-12-31 19:48:32 -0600247If you need to rebuild ``cryptography`` for any reason be sure to clear the
248local `wheel cache`_.
249
Alex Gaynoreb50a2c2014-05-02 09:38:33 -0700250Building cryptography with conda
251--------------------------------
252
Alex Gaynore51236d2016-11-06 10:13:35 -0500253Because of a bug in conda, attempting to install cryptography out of the box
David Reide162e262014-05-07 16:21:00 -0700254will result in an error. This can be resolved by setting the library path
255environment variable for your platform.
David Reide43861d2014-05-07 16:19:08 -0700256
Paul Kehrer524e7452017-03-09 19:18:24 -0400257On macOS:
Alex Gaynord8fc2572014-05-02 10:33:36 -0700258
259.. code-block:: console
260
261 $ env DYLD_LIBRARY_PATH="$HOME/anaconda/lib" pip install cryptography
262
David Reid18563e62014-05-07 16:20:09 -0700263and on Linux:
David Reide43861d2014-05-07 16:19:08 -0700264
265.. code-block:: console
266
267 $ env LD_LIBRARY_PATH="$HOME/anaconda/lib" pip install cryptography
268
Alex Gaynord8fc2572014-05-02 10:33:36 -0700269You will need to set this variable every time you start Python. For more
Alex Gaynorf65cba22014-05-02 10:40:57 -0700270information, consult `Greg Wilson's blog post`_ on the subject.
Alex Gaynoreb50a2c2014-05-02 09:38:33 -0700271
272
Alex Gaynor5ad6df92017-02-18 12:52:50 -0500273.. _`Homebrew`: https://brew.sh
Alex Gaynor3197ab52015-10-02 06:33:11 -0700274.. _`MacPorts`: https://www.macports.org
Paul Kehrer5a284e62017-05-29 17:09:23 -0500275.. _`openssl-release`: https://ci.cryptography.io/job/cryptography-support-jobs/job/openssl-release-1.1/
Alex Gaynor6422d832016-03-06 21:40:57 -0500276.. _`Greg Wilson's blog post`: https://software-carpentry.org/blog/2014/04/mr-biczo-was-right.html
Cory Benfieldba8f6382015-10-07 15:07:47 +0100277.. _virtualenv: https://virtualenv.pypa.io/en/latest/
Alex Gaynor769d5c62016-11-06 04:30:36 -0500278.. _openssl.org: https://www.openssl.org/source/
Paul Kehrerd4ea53b2015-12-31 19:48:32 -0600279.. _`wheel cache`: https://pip.pypa.io/en/stable/reference/pip_install/#caching