blob: 8acac2ec0e4f541dfd49fb2423ce4e35b1e13733 [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 Gaynor31b5d782016-12-23 12:20:36 -050013Currently we test ``cryptography`` on Python 2.6, 2.7, 3.3, 3.4, 3.5, 3.6, and
14PyPy 2.6+ on these operating systems.
Alex Stapletonb4684172014-03-15 18:02:13 +000015
Alex Gaynor1252dec2016-06-18 11:11:57 -040016* x86-64 CentOS 7.x, 6.4
Paul Kehrerbd88ee62015-02-20 10:38:31 -060017* x86-64 FreeBSD 10
Alex Gaynor2240ba22017-05-20 13:23:15 -070018* macOS 10.12 Sierra, 10.11 El Capitan, 10.10 Yosemite, 10.9 Mavericks
Paul Kehrerda742982015-10-01 21:10:26 -050019* x86-64 Ubuntu 12.04 LTS and Ubuntu 14.04 LTS
20* x86-64 Debian Wheezy (7.x), Jessie (8.x), and Debian Sid (unstable)
21* 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
Alex Gaynordb511142017-05-22 20:53:47 -070027 Python 3.3 support will be removed in the next cryptography release.
28
Paul Kehrerfb8dcdb2014-04-20 19:25:18 -050029We test compiling with ``clang`` as well as ``gcc`` and use the following
30OpenSSL releases:
31
Paul Kehrerfb8dcdb2014-04-20 19:25:18 -050032* ``OpenSSL 1.0.1``
Paul Kehrere683dee2014-08-09 08:15:23 -100033* ``OpenSSL 1.0.1e-fips`` (``RHEL/CentOS 7``)
Paul Kehrer96a08272015-02-21 18:37:38 -060034* ``OpenSSL 1.0.1j-freebsd``
Paul Kehrerda742982015-10-01 21:10:26 -050035* ``OpenSSL 1.0.1f``
36* ``OpenSSL 1.0.2-latest``
Alex Gaynor7a158272016-12-18 16:49:47 -050037* ``OpenSSL 1.1.0-latest``
Paul Kehrerfb8dcdb2014-04-20 19:25:18 -050038
Nick Badger63bbf182016-09-03 10:10:36 -070039Building cryptography on Windows
40--------------------------------
Alex Gaynor84d5c6b2014-02-02 10:12:34 -080041
Paul Kehrer156360a2014-06-30 12:14:01 -060042The wheel package on Windows is a statically linked build (as of 0.5) so all
Nick Badger63bbf182016-09-03 10:10:36 -070043dependencies are included. To install ``cryptography``, you will typically
44just run
Paul Kehrer156360a2014-06-30 12:14:01 -060045
46.. code-block:: console
47
48 $ pip install cryptography
49
50If you prefer to compile it yourself you'll need to have OpenSSL installed.
Paul Kehrer6608b7e2015-07-24 21:52:17 +010051You can compile OpenSSL yourself as well or use the binaries we build for our
Paul Kehrer937aa472015-10-11 12:09:27 -050052release infrastructure (`openssl-release`_). Be sure to download the proper
53version for your architecture and Python (2010 works for Python 2.6, 2.7, 3.3,
Paul Kehrerf19fef12017-02-09 13:53:44 +080054and 3.4 while 2015 is required for 3.5 and above). Wherever you place your copy
Paul Kehrer6608b7e2015-07-24 21:52:17 +010055of OpenSSL you'll need to set the ``LIB`` and ``INCLUDE`` environment variables
56to include the proper locations. For example:
skeuomorfbc26efb2014-01-29 08:31:47 +020057
skeuomorfb0293bf2014-01-29 21:41:02 +020058.. code-block:: console
59
60 C:\> \path\to\vcvarsall.bat x86_amd64
Paul Kehrer6608b7e2015-07-24 21:52:17 +010061 C:\> set LIB=C:\OpenSSL-win64\lib;%LIB%
62 C:\> set INCLUDE=C:\OpenSSL-win64\include;%INCLUDE%
Paul Kehrerf19fef12017-02-09 13:53:44 +080063 C:\> set CRYPTOGRAPHY_WINDOWS_LINK_OPENSSL110=1
Paul Kehrer2a39f7f2014-07-02 22:56:01 -050064 C:\> pip install cryptography
65
Paul Kehrerf19fef12017-02-09 13:53:44 +080066As of OpenSSL 1.1.0 the library names have changed from ``libeay32`` and
67``ssleay32`` to ``libcrypto`` and ``libssl`` (matching their names on all other
68platforms). Due to this change when linking against 1.1.0 you **must** set
69``CRYPTOGRAPHY_WINDOWS_LINK_OPENSSL110`` or else installation will fail.
70
Paul Kehrerd4ea53b2015-12-31 19:48:32 -060071If you need to rebuild ``cryptography`` for any reason be sure to clear the
72local `wheel cache`_.
skeuomorfbc26efb2014-01-29 08:31:47 +020073
Cory Benfield6d447282015-10-07 14:50:50 +010074.. _build-on-linux:
75
Chris Glass2e15c7f2014-02-13 19:10:10 +010076Building cryptography on Linux
77------------------------------
Chris Glass87c4edb2014-02-13 09:34:21 +010078
Chris Glass2e15c7f2014-02-13 19:10:10 +010079``cryptography`` should build very easily on Linux provided you have a C
Alex Gaynor49923842014-02-13 10:32:56 -080080compiler, headers for Python (if you're not using ``pypy``), and headers for
81the OpenSSL and ``libffi`` libraries available on your system.
Chris Glass87c4edb2014-02-13 09:34:21 +010082
Ayrxd9702f92014-02-15 23:57:13 +080083For Debian and Ubuntu, the following command will ensure that the required
Alex Gaynord0c69832017-01-21 09:20:54 -050084dependencies are installed (replace ``python-dev`` with ``python3-dev`` if
85you're using Python 3):
Chris Glass87c4edb2014-02-13 09:34:21 +010086
87.. code-block:: console
88
Alex Gaynor49923842014-02-13 10:32:56 -080089 $ sudo apt-get install build-essential libssl-dev libffi-dev python-dev
Chris Glass87c4edb2014-02-13 09:34:21 +010090
Ayrxd9702f92014-02-15 23:57:13 +080091For Fedora and RHEL-derivatives, the following command will ensure that the
Alex Gaynord0c69832017-01-21 09:20:54 -050092required dependencies are installed (replace ``python-devel`` with
93``python3-devel`` if you're using Python 3):
Ayrxa674c6b2014-02-15 21:24:23 +080094
95.. code-block:: console
96
97 $ sudo yum install gcc libffi-devel python-devel openssl-devel
98
Chris Glass87c4edb2014-02-13 09:34:21 +010099You should now be able to build and install cryptography with the usual
100
101.. code-block:: console
102
Alex Gaynor49923842014-02-13 10:32:56 -0800103 $ pip install cryptography
Chris Glass87c4edb2014-02-13 09:34:21 +0100104
Alex Gaynoreb50a2c2014-05-02 09:38:33 -0700105
Chris Glass2e15c7f2014-02-13 19:10:10 +0100106Using your own OpenSSL on Linux
107~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
skeuomorfbc26efb2014-01-29 08:31:47 +0200108
109Python links to OpenSSL for its own purposes and this can sometimes cause
110problems when you wish to use a different version of OpenSSL with cryptography.
111If you want to use cryptography with your own build of OpenSSL you will need to
112make sure that the build is configured correctly so that your version of
113OpenSSL doesn't conflict with Python's.
114
115The options you need to add allow the linker to identify every symbol correctly
116even when multiple versions of the library are linked into the same program. If
117you are using your distribution's source packages these will probably be
118patched in for you already, otherwise you'll need to use options something like
119this when configuring OpenSSL:
120
121.. code-block:: console
122
123 $ ./config -Wl,--version-script=openssl.ld -Wl,-Bsymbolic-functions -fPIC shared
124
125You'll also need to generate your own ``openssl.ld`` file. For example::
126
Alex Gaynor46c0c622017-03-22 22:56:26 -0400127 OPENSSL_1.1.0E_CUSTOM {
skeuomorfbc26efb2014-01-29 08:31:47 +0200128 global:
129 *;
130 };
131
132You should replace the version string on the first line as appropriate for your
133build.
134
Cory Benfield6d447282015-10-07 14:50:50 +0100135Static Wheels
136~~~~~~~~~~~~~
137
Paul Kehrer524e7452017-03-09 19:18:24 -0400138Cryptography ships statically-linked wheels for macOS and Windows, ensuring
139that these platforms can always use the most-recent OpenSSL, regardless of what
140is shipped by default on those platforms. As a result of various difficulties
Cory Benfield6d447282015-10-07 14:50:50 +0100141around Linux binary linking, Cryptography cannot do the same on Linux.
142
143However, you can build your own statically-linked wheels that will work on your
144own systems. This will allow you to continue to use relatively old Linux
145distributions (such as LTS releases), while making sure you have the most
146recent OpenSSL available to your Python programs.
147
148To do so, you should find yourself a machine that is as similar as possible to
149your target environment (e.g. your production environment): for example, spin
150up a new cloud server running your target Linux distribution. On this machine,
151install the Cryptography dependencies as mentioned in :ref:`build-on-linux`.
152Please also make sure you have `virtualenv`_ installed: this should be
153available from your system package manager.
154
Cory Benfield80781842015-10-07 15:07:57 +0100155Then, paste the following into a shell script. You'll need to populate the
156``OPENSSL_VERSION`` variable. To do that, visit `openssl.org`_ and find the
157latest non-FIPS release version number, then set the string appropriately. For
Alex Gaynor46c0c622017-03-22 22:56:26 -0400158example, for OpenSSL 1.0.2k, use ``OPENSSL_VERSION="1.0.2k"``.
Cory Benfield6d447282015-10-07 14:50:50 +0100159
160When this shell script is complete, you'll find a collection of wheel files in
161a directory called ``wheelhouse``. These wheels can be installed by a
162sufficiently-recent version of ``pip``. The Cryptography wheel in this
163directory contains a statically-linked OpenSSL binding, which ensures that you
164have access to the most-recent OpenSSL releases without corrupting your system
165dependencies.
166
167.. code-block:: console
168
169 set -e
170
Cory Benfield80781842015-10-07 15:07:57 +0100171 OPENSSL_VERSION="VERSIONGOESHERE"
Cory Benfield6d447282015-10-07 14:50:50 +0100172 CWD=$(pwd)
173
174 virtualenv env
175 . env/bin/activate
176 pip install -U setuptools
177 pip install -U wheel pip
Matt Thomasa187c972016-10-03 17:48:31 -0400178 curl -O https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz
Cory Benfield6d447282015-10-07 14:50:50 +0100179 tar xvf openssl-${OPENSSL_VERSION}.tar.gz
180 cd openssl-${OPENSSL_VERSION}
Alex Gaynor46c0c622017-03-22 22:56:26 -0400181 ./config no-shared no-ssl2 no-ssl3 -fPIC --prefix=${CWD}/openssl
Cory Benfield6d447282015-10-07 14:50:50 +0100182 make && make install
183 cd ..
Cory Benfield09d1b472015-10-16 08:14:42 +0100184 CFLAGS="-I${CWD}/openssl/include" LDFLAGS="-L${CWD}/openssl/lib" pip wheel --no-use-wheel cryptography
Cory Benfield6d447282015-10-07 14:50:50 +0100185
Paul Kehrer524e7452017-03-09 19:18:24 -0400186Building cryptography on macOS
187------------------------------
Paul Kehrer451c8df2015-07-04 11:03:27 -0500188
Paul Kehrera17d5902016-03-20 22:29:17 -0400189.. note::
190
191 If installation gives a ``fatal error: 'openssl/aes.h' file not found``
192 see the :doc:`FAQ </faq>` for information about how to fix this issue.
193
Paul Kehrer524e7452017-03-09 19:18:24 -0400194The wheel package on macOS is a statically linked build (as of 1.0.1) so for
Paul Kehrera17d5902016-03-20 22:29:17 -0400195users with pip 8 or above you only need one step:
Paul Kehrer451c8df2015-07-04 11:03:27 -0500196
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500197.. code-block:: console
skeuomorfbc26efb2014-01-29 08:31:47 +0200198
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500199 $ pip install cryptography
200
Paul Kehrer524e7452017-03-09 19:18:24 -0400201If you want to build cryptography yourself or are on an older macOS version,
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500202cryptography requires the presence of a C compiler, development headers, and
Paul Kehrer524e7452017-03-09 19:18:24 -0400203the proper libraries. On macOS much of this is provided by Apple's Xcode
204development tools. To install the Xcode command line tools (on macOS 10.9+)
Paul Kehrerb29f4642015-12-31 23:27:25 -0600205open a terminal window and run:
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500206
207.. code-block:: console
208
209 $ xcode-select --install
210
211This will install a compiler (clang) along with (most of) the required
212development headers.
213
214You'll also need OpenSSL, which you can obtain from `Homebrew`_ or `MacPorts`_.
Paul Kehrer355174a2015-12-22 09:47:26 -0600215Cryptography does **not** support Apple's deprecated OpenSSL distribution.
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500216
217To build cryptography and dynamically link it:
Ayrx1ced5b82014-04-08 19:41:26 +0800218
219`Homebrew`_
skeuomorfbc26efb2014-01-29 08:31:47 +0200220
221.. code-block:: console
222
Paul Kehrer524e7452017-03-09 19:18:24 -0400223 $ brew install openssl@1.1
224 $ 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 +0200225
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500226`MacPorts`_:
Kimmo Parviainen-Jalankoe01e0bf2014-03-19 18:57:09 +0200227
228.. code-block:: console
229
230 $ sudo port install openssl
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500231 $ env LDFLAGS="-L/opt/local/lib" CFLAGS="-I/opt/local/include" pip install cryptography
232
233You can also build cryptography statically:
234
235`Homebrew`_
236
237.. code-block:: console
238
Paul Kehrer524e7452017-03-09 19:18:24 -0400239 $ brew install openssl@1.1
240 $ env CRYPTOGRAPHY_OSX_NO_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 -0500241
242`MacPorts`_:
243
244.. code-block:: console
245
246 $ sudo port install openssl
247 $ 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 +0200248
Paul Kehrerd4ea53b2015-12-31 19:48:32 -0600249If you need to rebuild ``cryptography`` for any reason be sure to clear the
250local `wheel cache`_.
251
Alex Gaynoreb50a2c2014-05-02 09:38:33 -0700252Building cryptography with conda
253--------------------------------
254
Alex Gaynore51236d2016-11-06 10:13:35 -0500255Because of a bug in conda, attempting to install cryptography out of the box
David Reide162e262014-05-07 16:21:00 -0700256will result in an error. This can be resolved by setting the library path
257environment variable for your platform.
David Reide43861d2014-05-07 16:19:08 -0700258
Paul Kehrer524e7452017-03-09 19:18:24 -0400259On macOS:
Alex Gaynord8fc2572014-05-02 10:33:36 -0700260
261.. code-block:: console
262
263 $ env DYLD_LIBRARY_PATH="$HOME/anaconda/lib" pip install cryptography
264
David Reid18563e62014-05-07 16:20:09 -0700265and on Linux:
David Reide43861d2014-05-07 16:19:08 -0700266
267.. code-block:: console
268
269 $ env LD_LIBRARY_PATH="$HOME/anaconda/lib" pip install cryptography
270
Alex Gaynord8fc2572014-05-02 10:33:36 -0700271You will need to set this variable every time you start Python. For more
Alex Gaynorf65cba22014-05-02 10:40:57 -0700272information, consult `Greg Wilson's blog post`_ on the subject.
Alex Gaynoreb50a2c2014-05-02 09:38:33 -0700273
274
Alex Gaynor5ad6df92017-02-18 12:52:50 -0500275.. _`Homebrew`: https://brew.sh
Alex Gaynor3197ab52015-10-02 06:33:11 -0700276.. _`MacPorts`: https://www.macports.org
Paul Kehrer937aa472015-10-11 12:09:27 -0500277.. _`openssl-release`: https://jenkins.cryptography.io/job/openssl-release/
Alex Gaynor6422d832016-03-06 21:40:57 -0500278.. _`Greg Wilson's blog post`: https://software-carpentry.org/blog/2014/04/mr-biczo-was-right.html
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