blob: cb876b8fa8f43423366fc5bfba1d3e7c361025b6 [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 Gaynora26c13a2015-09-25 17:52:06 -040013Currently we test ``cryptography`` on Python 2.6, 2.7, 3.3, 3.4, 3.5, and PyPy
142.6+ on these operating systems.
Alex Stapletonb4684172014-03-15 18:02:13 +000015
Paul Kehrer73667de2014-07-14 12:33:27 -050016* x86-64 CentOS 7.x, 6.4 and CentOS 5.x
Paul Kehrerbd88ee62015-02-20 10:38:31 -060017* x86-64 FreeBSD 10
Paul Kehrerda742982015-10-01 21:10:26 -050018* OS X 10.11 El Capitan, 10.10 Yosemite, 10.9 Mavericks, 10.8 Mountain Lion,
19 and 10.7 Lion
20* x86-64 Ubuntu 12.04 LTS and Ubuntu 14.04 LTS
21* x86-64 Debian Wheezy (7.x), Jessie (8.x), and Debian Sid (unstable)
22* 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::
25 Python 2.6 is no longer supported by the Python core team. A future version
26 of cryptography will drop support for this version.
27
Paul Kehrerfb8dcdb2014-04-20 19:25:18 -050028We test compiling with ``clang`` as well as ``gcc`` and use the following
29OpenSSL releases:
30
31* ``OpenSSL 0.9.8e-fips-rhel5`` (``RHEL/CentOS 5``)
Alex Stapleton2c688a42014-05-04 15:22:29 +010032* ``OpenSSL 0.9.8k``
Paul Kehrerfb8dcdb2014-04-20 19:25:18 -050033* ``OpenSSL 1.0.0-fips`` (``RHEL/CentOS 6.4``)
34* ``OpenSSL 1.0.1``
Paul Kehrere683dee2014-08-09 08:15:23 -100035* ``OpenSSL 1.0.1e-fips`` (``RHEL/CentOS 7``)
Paul Kehrer96a08272015-02-21 18:37:38 -060036* ``OpenSSL 1.0.1j-freebsd``
Paul Kehrerda742982015-10-01 21:10:26 -050037* ``OpenSSL 1.0.1f``
38* ``OpenSSL 1.0.2-latest``
Paul Kehrerfb8dcdb2014-04-20 19:25:18 -050039
Paul Kehrer56b360a2015-12-31 19:59:25 -060040.. warning::
41 OpenSSL versions 0.9.8 and 1.0.0 are no longer supported by the OpenSSL
Alex Gaynorfd36f9d2016-03-19 12:15:12 -040042 project. Cryptography 1.4 has dropped support for OpenSSL 0.9.8, see the
43 :doc:`FAQ </faq>` for more details.
Paul Kehrer56b360a2015-12-31 19:59:25 -060044
skeuomorfbc26efb2014-01-29 08:31:47 +020045On Windows
46----------
Alex Gaynor84d5c6b2014-02-02 10:12:34 -080047
Paul Kehrer156360a2014-06-30 12:14:01 -060048The wheel package on Windows is a statically linked build (as of 0.5) so all
49dependencies are included. Just run
50
51.. code-block:: console
52
53 $ pip install cryptography
54
55If you prefer to compile it yourself you'll need to have OpenSSL installed.
Paul Kehrer6608b7e2015-07-24 21:52:17 +010056You can compile OpenSSL yourself as well or use the binaries we build for our
Paul Kehrer937aa472015-10-11 12:09:27 -050057release infrastructure (`openssl-release`_). Be sure to download the proper
58version for your architecture and Python (2010 works for Python 2.6, 2.7, 3.3,
59and 3.4 while 2015 is required for 3.5). Wherever you place your copy
Paul Kehrer6608b7e2015-07-24 21:52:17 +010060of OpenSSL you'll need to set the ``LIB`` and ``INCLUDE`` environment variables
61to include the proper locations. For example:
skeuomorfbc26efb2014-01-29 08:31:47 +020062
skeuomorfb0293bf2014-01-29 21:41:02 +020063.. code-block:: console
64
65 C:\> \path\to\vcvarsall.bat x86_amd64
Paul Kehrer6608b7e2015-07-24 21:52:17 +010066 C:\> set LIB=C:\OpenSSL-win64\lib;%LIB%
67 C:\> set INCLUDE=C:\OpenSSL-win64\include;%INCLUDE%
Paul Kehrer2a39f7f2014-07-02 22:56:01 -050068 C:\> pip install cryptography
69
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
Chris Glass2e15c7f2014-02-13 19:10:10 +010078``cryptography`` should build very easily on Linux provided you have a C
Alex Gaynor49923842014-02-13 10:32:56 -080079compiler, headers for Python (if you're not using ``pypy``), and headers for
80the OpenSSL and ``libffi`` libraries available on your system.
Chris Glass87c4edb2014-02-13 09:34:21 +010081
Ayrxd9702f92014-02-15 23:57:13 +080082For Debian and Ubuntu, the following command will ensure that the required
Chris Glassf82d94f2014-02-13 11:46:49 +010083dependencies are installed:
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
90required dependencies are installed:
Ayrxa674c6b2014-02-15 21:24:23 +080091
92.. code-block:: console
93
94 $ sudo yum install gcc libffi-devel python-devel openssl-devel
95
Chris Glass87c4edb2014-02-13 09:34:21 +010096You should now be able to build and install cryptography with the usual
97
98.. code-block:: console
99
Alex Gaynor49923842014-02-13 10:32:56 -0800100 $ pip install cryptography
Chris Glass87c4edb2014-02-13 09:34:21 +0100101
Alex Gaynoreb50a2c2014-05-02 09:38:33 -0700102
Chris Glass2e15c7f2014-02-13 19:10:10 +0100103Using your own OpenSSL on Linux
104~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
skeuomorfbc26efb2014-01-29 08:31:47 +0200105
106Python links to OpenSSL for its own purposes and this can sometimes cause
107problems when you wish to use a different version of OpenSSL with cryptography.
108If you want to use cryptography with your own build of OpenSSL you will need to
109make sure that the build is configured correctly so that your version of
110OpenSSL doesn't conflict with Python's.
111
112The options you need to add allow the linker to identify every symbol correctly
113even when multiple versions of the library are linked into the same program. If
114you are using your distribution's source packages these will probably be
115patched in for you already, otherwise you'll need to use options something like
116this when configuring OpenSSL:
117
118.. code-block:: console
119
120 $ ./config -Wl,--version-script=openssl.ld -Wl,-Bsymbolic-functions -fPIC shared
121
122You'll also need to generate your own ``openssl.ld`` file. For example::
123
124 OPENSSL_1.0.1F_CUSTOM {
125 global:
126 *;
127 };
128
129You should replace the version string on the first line as appropriate for your
130build.
131
Cory Benfield6d447282015-10-07 14:50:50 +0100132Static Wheels
133~~~~~~~~~~~~~
134
135Cryptography ships statically-linked wheels for OS X and Windows, ensuring that
136these platforms can always use the most-recent OpenSSL, regardless of what is
137shipped by default on those platforms. As a result of various difficulties
138around Linux binary linking, Cryptography cannot do the same on Linux.
139
140However, you can build your own statically-linked wheels that will work on your
141own systems. This will allow you to continue to use relatively old Linux
142distributions (such as LTS releases), while making sure you have the most
143recent OpenSSL available to your Python programs.
144
145To do so, you should find yourself a machine that is as similar as possible to
146your target environment (e.g. your production environment): for example, spin
147up a new cloud server running your target Linux distribution. On this machine,
148install the Cryptography dependencies as mentioned in :ref:`build-on-linux`.
149Please also make sure you have `virtualenv`_ installed: this should be
150available from your system package manager.
151
Cory Benfield80781842015-10-07 15:07:57 +0100152Then, paste the following into a shell script. You'll need to populate the
153``OPENSSL_VERSION`` variable. To do that, visit `openssl.org`_ and find the
154latest non-FIPS release version number, then set the string appropriately. For
155example, for OpenSSL 1.0.2d, use ``OPENSSL_VERSION="1.0.2d"``.
Cory Benfield6d447282015-10-07 14:50:50 +0100156
157When this shell script is complete, you'll find a collection of wheel files in
158a directory called ``wheelhouse``. These wheels can be installed by a
159sufficiently-recent version of ``pip``. The Cryptography wheel in this
160directory contains a statically-linked OpenSSL binding, which ensures that you
161have access to the most-recent OpenSSL releases without corrupting your system
162dependencies.
163
164.. code-block:: console
165
166 set -e
167
Cory Benfield80781842015-10-07 15:07:57 +0100168 OPENSSL_VERSION="VERSIONGOESHERE"
Cory Benfield6d447282015-10-07 14:50:50 +0100169 CWD=$(pwd)
170
171 virtualenv env
172 . env/bin/activate
173 pip install -U setuptools
174 pip install -U wheel pip
175 curl -O https://openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz
176 tar xvf openssl-${OPENSSL_VERSION}.tar.gz
177 cd openssl-${OPENSSL_VERSION}
178 ./config no-shared no-ssl2 -fPIC --prefix=${CWD}/openssl
179 make && make install
180 cd ..
Cory Benfield09d1b472015-10-16 08:14:42 +0100181 CFLAGS="-I${CWD}/openssl/include" LDFLAGS="-L${CWD}/openssl/lib" pip wheel --no-use-wheel cryptography
Cory Benfield6d447282015-10-07 14:50:50 +0100182
Paul Kehrer451c8df2015-07-04 11:03:27 -0500183Building cryptography on OS X
184-----------------------------
185
Paul Kehrera17d5902016-03-20 22:29:17 -0400186.. note::
187
188 If installation gives a ``fatal error: 'openssl/aes.h' file not found``
189 see the :doc:`FAQ </faq>` for information about how to fix this issue.
190
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500191The wheel package on OS X is a statically linked build (as of 1.0.1) so for
Paul Kehrera17d5902016-03-20 22:29:17 -0400192users with pip 8 or above you only need one step:
Paul Kehrer451c8df2015-07-04 11:03:27 -0500193
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500194.. code-block:: console
skeuomorfbc26efb2014-01-29 08:31:47 +0200195
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500196 $ pip install cryptography
197
198If you want to build cryptography yourself or are on an older OS X version
199cryptography requires the presence of a C compiler, development headers, and
200the proper libraries. On OS X much of this is provided by Apple's Xcode
Paul Kehrerb29f4642015-12-31 23:27:25 -0600201development tools. To install the Xcode command line tools (on OS X 10.9+)
202open a terminal window and run:
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500203
204.. code-block:: console
205
206 $ xcode-select --install
207
208This will install a compiler (clang) along with (most of) the required
209development headers.
210
211You'll also need OpenSSL, which you can obtain from `Homebrew`_ or `MacPorts`_.
Paul Kehrer355174a2015-12-22 09:47:26 -0600212Cryptography does **not** support Apple's deprecated OpenSSL distribution.
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500213
214To build cryptography and dynamically link it:
Ayrx1ced5b82014-04-08 19:41:26 +0800215
216`Homebrew`_
skeuomorfbc26efb2014-01-29 08:31:47 +0200217
218.. code-block:: console
219
220 $ brew install openssl
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500221 $ env LDFLAGS="-L$(brew --prefix openssl)/lib" CFLAGS="-I$(brew --prefix openssl)/include" pip install cryptography
skeuomorfbc26efb2014-01-29 08:31:47 +0200222
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500223`MacPorts`_:
Kimmo Parviainen-Jalankoe01e0bf2014-03-19 18:57:09 +0200224
225.. code-block:: console
226
227 $ sudo port install openssl
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500228 $ env LDFLAGS="-L/opt/local/lib" CFLAGS="-I/opt/local/include" pip install cryptography
229
230You can also build cryptography statically:
231
232`Homebrew`_
233
234.. code-block:: console
235
236 $ brew install openssl
237 $ env CRYPTOGRAPHY_OSX_NO_LINK_FLAGS=1 LDFLAGS="$(brew --prefix openssl)/lib/libssl.a $(brew --prefix openssl)/lib/libcrypto.a" CFLAGS="-I$(brew --prefix openssl)/include" pip install cryptography
238
239`MacPorts`_:
240
241.. code-block:: console
242
243 $ sudo port install openssl
244 $ 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 +0200245
Paul Kehrerd4ea53b2015-12-31 19:48:32 -0600246If you need to rebuild ``cryptography`` for any reason be sure to clear the
247local `wheel cache`_.
248
Alex Gaynoreb50a2c2014-05-02 09:38:33 -0700249Building cryptography with conda
250--------------------------------
251
Alex Gaynord6948382014-05-02 14:10:14 -0700252Because of a `bug in conda`_, attempting to install cryptography out of the box
David Reide162e262014-05-07 16:21:00 -0700253will result in an error. This can be resolved by setting the library path
254environment variable for your platform.
David Reide43861d2014-05-07 16:19:08 -0700255
256On OS X:
Alex Gaynord8fc2572014-05-02 10:33:36 -0700257
258.. code-block:: console
259
260 $ env DYLD_LIBRARY_PATH="$HOME/anaconda/lib" pip install cryptography
261
David Reid18563e62014-05-07 16:20:09 -0700262and on Linux:
David Reide43861d2014-05-07 16:19:08 -0700263
264.. code-block:: console
265
266 $ env LD_LIBRARY_PATH="$HOME/anaconda/lib" pip install cryptography
267
Alex Gaynord8fc2572014-05-02 10:33:36 -0700268You will need to set this variable every time you start Python. For more
Alex Gaynorf65cba22014-05-02 10:40:57 -0700269information, consult `Greg Wilson's blog post`_ on the subject.
Alex Gaynoreb50a2c2014-05-02 09:38:33 -0700270
271
skeuomorfbc26efb2014-01-29 08:31:47 +0200272.. _`Homebrew`: http://brew.sh
Alex Gaynor3197ab52015-10-02 06:33:11 -0700273.. _`MacPorts`: https://www.macports.org
Paul Kehrer937aa472015-10-11 12:09:27 -0500274.. _`openssl-release`: https://jenkins.cryptography.io/job/openssl-release/
Alex Gaynord6948382014-05-02 14:10:14 -0700275.. _`bug in conda`: https://github.com/conda/conda-recipes/issues/110
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/
Cory Benfield3ed8b812015-10-07 15:18:12 +0100278.. _openssl.org: https://openssl.org/source/
Paul Kehrerd4ea53b2015-12-31 19:48:32 -0600279.. _`wheel cache`: https://pip.pypa.io/en/stable/reference/pip_install/#caching