blob: 330817c7117149b1736760e2c59f72824b216829 [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
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
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
Paul Kehrerfb8dcdb2014-04-20 19:25:18 -050031* ``OpenSSL 1.0.0-fips`` (``RHEL/CentOS 6.4``)
32* ``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``
Paul Kehrer07ea3cd2016-08-26 21:48:24 +080037* ``OpenSSL 1.1.0``
Paul Kehrerfb8dcdb2014-04-20 19:25:18 -050038
Paul Kehrer56b360a2015-12-31 19:59:25 -060039.. warning::
Alex Gaynor1252dec2016-06-18 11:11:57 -040040 OpenSSL 1.0.0 is no longer supported by the OpenSSL project. Cryptography
Alex Gaynor3b83fc22016-08-26 22:11:50 -040041 will drop support for it in the next release.
Paul Kehrer56b360a2015-12-31 19:59:25 -060042
skeuomorfbc26efb2014-01-29 08:31:47 +020043On Windows
44----------
Alex Gaynor84d5c6b2014-02-02 10:12:34 -080045
Paul Kehrer156360a2014-06-30 12:14:01 -060046The wheel package on Windows is a statically linked build (as of 0.5) so all
47dependencies are included. Just run
48
49.. code-block:: console
50
51 $ pip install cryptography
52
53If you prefer to compile it yourself you'll need to have OpenSSL installed.
Paul Kehrer6608b7e2015-07-24 21:52:17 +010054You can compile OpenSSL yourself as well or use the binaries we build for our
Paul Kehrer937aa472015-10-11 12:09:27 -050055release infrastructure (`openssl-release`_). Be sure to download the proper
56version for your architecture and Python (2010 works for Python 2.6, 2.7, 3.3,
57and 3.4 while 2015 is required for 3.5). Wherever you place your copy
Paul Kehrer6608b7e2015-07-24 21:52:17 +010058of OpenSSL you'll need to set the ``LIB`` and ``INCLUDE`` environment variables
59to include the proper locations. For example:
skeuomorfbc26efb2014-01-29 08:31:47 +020060
skeuomorfb0293bf2014-01-29 21:41:02 +020061.. code-block:: console
62
63 C:\> \path\to\vcvarsall.bat x86_amd64
Paul Kehrer6608b7e2015-07-24 21:52:17 +010064 C:\> set LIB=C:\OpenSSL-win64\lib;%LIB%
65 C:\> set INCLUDE=C:\OpenSSL-win64\include;%INCLUDE%
Paul Kehrer2a39f7f2014-07-02 22:56:01 -050066 C:\> pip install cryptography
67
Paul Kehrerd4ea53b2015-12-31 19:48:32 -060068If you need to rebuild ``cryptography`` for any reason be sure to clear the
69local `wheel cache`_.
skeuomorfbc26efb2014-01-29 08:31:47 +020070
Cory Benfield6d447282015-10-07 14:50:50 +010071.. _build-on-linux:
72
Chris Glass2e15c7f2014-02-13 19:10:10 +010073Building cryptography on Linux
74------------------------------
Chris Glass87c4edb2014-02-13 09:34:21 +010075
Chris Glass2e15c7f2014-02-13 19:10:10 +010076``cryptography`` should build very easily on Linux provided you have a C
Alex Gaynor49923842014-02-13 10:32:56 -080077compiler, headers for Python (if you're not using ``pypy``), and headers for
78the OpenSSL and ``libffi`` libraries available on your system.
Chris Glass87c4edb2014-02-13 09:34:21 +010079
Ayrxd9702f92014-02-15 23:57:13 +080080For Debian and Ubuntu, the following command will ensure that the required
Chris Glassf82d94f2014-02-13 11:46:49 +010081dependencies are installed:
Chris Glass87c4edb2014-02-13 09:34:21 +010082
83.. code-block:: console
84
Alex Gaynor49923842014-02-13 10:32:56 -080085 $ sudo apt-get install build-essential libssl-dev libffi-dev python-dev
Chris Glass87c4edb2014-02-13 09:34:21 +010086
Ayrxd9702f92014-02-15 23:57:13 +080087For Fedora and RHEL-derivatives, the following command will ensure that the
88required dependencies are installed:
Ayrxa674c6b2014-02-15 21:24:23 +080089
90.. code-block:: console
91
92 $ sudo yum install gcc libffi-devel python-devel openssl-devel
93
Chris Glass87c4edb2014-02-13 09:34:21 +010094You should now be able to build and install cryptography with the usual
95
96.. code-block:: console
97
Alex Gaynor49923842014-02-13 10:32:56 -080098 $ pip install cryptography
Chris Glass87c4edb2014-02-13 09:34:21 +010099
Alex Gaynoreb50a2c2014-05-02 09:38:33 -0700100
Chris Glass2e15c7f2014-02-13 19:10:10 +0100101Using your own OpenSSL on Linux
102~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
skeuomorfbc26efb2014-01-29 08:31:47 +0200103
104Python links to OpenSSL for its own purposes and this can sometimes cause
105problems when you wish to use a different version of OpenSSL with cryptography.
106If you want to use cryptography with your own build of OpenSSL you will need to
107make sure that the build is configured correctly so that your version of
108OpenSSL doesn't conflict with Python's.
109
110The options you need to add allow the linker to identify every symbol correctly
111even when multiple versions of the library are linked into the same program. If
112you are using your distribution's source packages these will probably be
113patched in for you already, otherwise you'll need to use options something like
114this when configuring OpenSSL:
115
116.. code-block:: console
117
118 $ ./config -Wl,--version-script=openssl.ld -Wl,-Bsymbolic-functions -fPIC shared
119
120You'll also need to generate your own ``openssl.ld`` file. For example::
121
122 OPENSSL_1.0.1F_CUSTOM {
123 global:
124 *;
125 };
126
127You should replace the version string on the first line as appropriate for your
128build.
129
Cory Benfield6d447282015-10-07 14:50:50 +0100130Static Wheels
131~~~~~~~~~~~~~
132
133Cryptography ships statically-linked wheels for OS X and Windows, ensuring that
134these platforms can always use the most-recent OpenSSL, regardless of what is
135shipped by default on those platforms. As a result of various difficulties
136around Linux binary linking, Cryptography cannot do the same on Linux.
137
138However, you can build your own statically-linked wheels that will work on your
139own systems. This will allow you to continue to use relatively old Linux
140distributions (such as LTS releases), while making sure you have the most
141recent OpenSSL available to your Python programs.
142
143To do so, you should find yourself a machine that is as similar as possible to
144your target environment (e.g. your production environment): for example, spin
145up a new cloud server running your target Linux distribution. On this machine,
146install the Cryptography dependencies as mentioned in :ref:`build-on-linux`.
147Please also make sure you have `virtualenv`_ installed: this should be
148available from your system package manager.
149
Cory Benfield80781842015-10-07 15:07:57 +0100150Then, paste the following into a shell script. You'll need to populate the
151``OPENSSL_VERSION`` variable. To do that, visit `openssl.org`_ and find the
152latest non-FIPS release version number, then set the string appropriately. For
153example, for OpenSSL 1.0.2d, use ``OPENSSL_VERSION="1.0.2d"``.
Cory Benfield6d447282015-10-07 14:50:50 +0100154
155When this shell script is complete, you'll find a collection of wheel files in
156a directory called ``wheelhouse``. These wheels can be installed by a
157sufficiently-recent version of ``pip``. The Cryptography wheel in this
158directory contains a statically-linked OpenSSL binding, which ensures that you
159have access to the most-recent OpenSSL releases without corrupting your system
160dependencies.
161
162.. code-block:: console
163
164 set -e
165
Cory Benfield80781842015-10-07 15:07:57 +0100166 OPENSSL_VERSION="VERSIONGOESHERE"
Cory Benfield6d447282015-10-07 14:50:50 +0100167 CWD=$(pwd)
168
169 virtualenv env
170 . env/bin/activate
171 pip install -U setuptools
172 pip install -U wheel pip
173 curl -O https://openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz
174 tar xvf openssl-${OPENSSL_VERSION}.tar.gz
175 cd openssl-${OPENSSL_VERSION}
176 ./config no-shared no-ssl2 -fPIC --prefix=${CWD}/openssl
177 make && make install
178 cd ..
Cory Benfield09d1b472015-10-16 08:14:42 +0100179 CFLAGS="-I${CWD}/openssl/include" LDFLAGS="-L${CWD}/openssl/lib" pip wheel --no-use-wheel cryptography
Cory Benfield6d447282015-10-07 14:50:50 +0100180
Paul Kehrer451c8df2015-07-04 11:03:27 -0500181Building cryptography on OS X
182-----------------------------
183
Paul Kehrera17d5902016-03-20 22:29:17 -0400184.. note::
185
186 If installation gives a ``fatal error: 'openssl/aes.h' file not found``
187 see the :doc:`FAQ </faq>` for information about how to fix this issue.
188
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500189The wheel package on OS X is a statically linked build (as of 1.0.1) so for
Paul Kehrera17d5902016-03-20 22:29:17 -0400190users with pip 8 or above you only need one step:
Paul Kehrer451c8df2015-07-04 11:03:27 -0500191
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500192.. code-block:: console
skeuomorfbc26efb2014-01-29 08:31:47 +0200193
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500194 $ pip install cryptography
195
Akan Brown60cd5a62016-08-08 22:30:02 -0400196If you want to build cryptography yourself or are on an older OS X version,
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500197cryptography requires the presence of a C compiler, development headers, and
198the proper libraries. On OS X much of this is provided by Apple's Xcode
Paul Kehrerb29f4642015-12-31 23:27:25 -0600199development tools. To install the Xcode command line tools (on OS X 10.9+)
200open a terminal window and run:
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500201
202.. code-block:: console
203
204 $ xcode-select --install
205
206This will install a compiler (clang) along with (most of) the required
207development headers.
208
209You'll also need OpenSSL, which you can obtain from `Homebrew`_ or `MacPorts`_.
Paul Kehrer355174a2015-12-22 09:47:26 -0600210Cryptography does **not** support Apple's deprecated OpenSSL distribution.
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500211
212To build cryptography and dynamically link it:
Ayrx1ced5b82014-04-08 19:41:26 +0800213
214`Homebrew`_
skeuomorfbc26efb2014-01-29 08:31:47 +0200215
216.. code-block:: console
217
218 $ brew install openssl
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500219 $ env LDFLAGS="-L$(brew --prefix openssl)/lib" CFLAGS="-I$(brew --prefix openssl)/include" pip install cryptography
skeuomorfbc26efb2014-01-29 08:31:47 +0200220
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500221`MacPorts`_:
Kimmo Parviainen-Jalankoe01e0bf2014-03-19 18:57:09 +0200222
223.. code-block:: console
224
225 $ sudo port install openssl
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500226 $ env LDFLAGS="-L/opt/local/lib" CFLAGS="-I/opt/local/include" pip install cryptography
227
228You can also build cryptography statically:
229
230`Homebrew`_
231
232.. code-block:: console
233
234 $ brew install openssl
235 $ 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
236
237`MacPorts`_:
238
239.. code-block:: console
240
241 $ sudo port install openssl
242 $ 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 +0200243
Paul Kehrerd4ea53b2015-12-31 19:48:32 -0600244If you need to rebuild ``cryptography`` for any reason be sure to clear the
245local `wheel cache`_.
246
Alex Gaynoreb50a2c2014-05-02 09:38:33 -0700247Building cryptography with conda
248--------------------------------
249
Alex Gaynord6948382014-05-02 14:10:14 -0700250Because of a `bug in conda`_, attempting to install cryptography out of the box
David Reide162e262014-05-07 16:21:00 -0700251will result in an error. This can be resolved by setting the library path
252environment variable for your platform.
David Reide43861d2014-05-07 16:19:08 -0700253
254On OS X:
Alex Gaynord8fc2572014-05-02 10:33:36 -0700255
256.. code-block:: console
257
258 $ env DYLD_LIBRARY_PATH="$HOME/anaconda/lib" pip install cryptography
259
David Reid18563e62014-05-07 16:20:09 -0700260and on Linux:
David Reide43861d2014-05-07 16:19:08 -0700261
262.. code-block:: console
263
264 $ env LD_LIBRARY_PATH="$HOME/anaconda/lib" pip install cryptography
265
Alex Gaynord8fc2572014-05-02 10:33:36 -0700266You will need to set this variable every time you start Python. For more
Alex Gaynorf65cba22014-05-02 10:40:57 -0700267information, consult `Greg Wilson's blog post`_ on the subject.
Alex Gaynoreb50a2c2014-05-02 09:38:33 -0700268
269
skeuomorfbc26efb2014-01-29 08:31:47 +0200270.. _`Homebrew`: http://brew.sh
Alex Gaynor3197ab52015-10-02 06:33:11 -0700271.. _`MacPorts`: https://www.macports.org
Paul Kehrer937aa472015-10-11 12:09:27 -0500272.. _`openssl-release`: https://jenkins.cryptography.io/job/openssl-release/
Alex Gaynord6948382014-05-02 14:10:14 -0700273.. _`bug in conda`: https://github.com/conda/conda-recipes/issues/110
Alex Gaynor6422d832016-03-06 21:40:57 -0500274.. _`Greg Wilson's blog post`: https://software-carpentry.org/blog/2014/04/mr-biczo-was-right.html
Cory Benfieldba8f6382015-10-07 15:07:47 +0100275.. _virtualenv: https://virtualenv.pypa.io/en/latest/
Cory Benfield3ed8b812015-10-07 15:18:12 +0100276.. _openssl.org: https://openssl.org/source/
Paul Kehrerd4ea53b2015-12-31 19:48:32 -0600277.. _`wheel cache`: https://pip.pypa.io/en/stable/reference/pip_install/#caching