blob: 7f16313e5fda67e27641fb7540716fb77cec34c2 [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 Gaynorf7e12192016-12-02 19:34:12 -050018* OS X 10.12 Sierra, 10.11 El Capitan, 10.10 Yosemite, 10.9 Mavericks,
19 10.8 Mountain Lion, and 10.7 Lion
Paul Kehrerda742982015-10-01 21:10:26 -050020* 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.1``
Paul Kehrere683dee2014-08-09 08:15:23 -100032* ``OpenSSL 1.0.1e-fips`` (``RHEL/CentOS 7``)
Paul Kehrer96a08272015-02-21 18:37:38 -060033* ``OpenSSL 1.0.1j-freebsd``
Paul Kehrerda742982015-10-01 21:10:26 -050034* ``OpenSSL 1.0.1f``
35* ``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 Kehrerf19fef12017-02-09 13:53:44 +080062 C:\> set CRYPTOGRAPHY_WINDOWS_LINK_OPENSSL110=1
Paul Kehrer2a39f7f2014-07-02 22:56:01 -050063 C:\> pip install cryptography
64
Paul Kehrerf19fef12017-02-09 13:53:44 +080065As of OpenSSL 1.1.0 the library names have changed from ``libeay32`` and
66``ssleay32`` to ``libcrypto`` and ``libssl`` (matching their names on all other
67platforms). Due to this change when linking against 1.1.0 you **must** set
68``CRYPTOGRAPHY_WINDOWS_LINK_OPENSSL110`` or else installation will fail.
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
Alex Gaynord0c69832017-01-21 09:20:54 -050083dependencies are installed (replace ``python-dev`` with ``python3-dev`` if
84you're using Python 3):
Chris Glass87c4edb2014-02-13 09:34:21 +010085
86.. code-block:: console
87
Alex Gaynor49923842014-02-13 10:32:56 -080088 $ sudo apt-get install build-essential libssl-dev libffi-dev python-dev
Chris Glass87c4edb2014-02-13 09:34:21 +010089
Ayrxd9702f92014-02-15 23:57:13 +080090For Fedora and RHEL-derivatives, the following command will ensure that the
Alex Gaynord0c69832017-01-21 09:20:54 -050091required dependencies are installed (replace ``python-devel`` with
92``python3-devel`` if you're using Python 3):
Ayrxa674c6b2014-02-15 21:24:23 +080093
94.. code-block:: console
95
96 $ sudo yum install gcc libffi-devel python-devel openssl-devel
97
Chris Glass87c4edb2014-02-13 09:34:21 +010098You should now be able to build and install cryptography with the usual
99
100.. code-block:: console
101
Alex Gaynor49923842014-02-13 10:32:56 -0800102 $ pip install cryptography
Chris Glass87c4edb2014-02-13 09:34:21 +0100103
Alex Gaynoreb50a2c2014-05-02 09:38:33 -0700104
Chris Glass2e15c7f2014-02-13 19:10:10 +0100105Using your own OpenSSL on Linux
106~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
skeuomorfbc26efb2014-01-29 08:31:47 +0200107
108Python links to OpenSSL for its own purposes and this can sometimes cause
109problems when you wish to use a different version of OpenSSL with cryptography.
110If you want to use cryptography with your own build of OpenSSL you will need to
111make sure that the build is configured correctly so that your version of
112OpenSSL doesn't conflict with Python's.
113
114The options you need to add allow the linker to identify every symbol correctly
115even when multiple versions of the library are linked into the same program. If
116you are using your distribution's source packages these will probably be
117patched in for you already, otherwise you'll need to use options something like
118this when configuring OpenSSL:
119
120.. code-block:: console
121
122 $ ./config -Wl,--version-script=openssl.ld -Wl,-Bsymbolic-functions -fPIC shared
123
124You'll also need to generate your own ``openssl.ld`` file. For example::
125
126 OPENSSL_1.0.1F_CUSTOM {
127 global:
128 *;
129 };
130
131You should replace the version string on the first line as appropriate for your
132build.
133
Cory Benfield6d447282015-10-07 14:50:50 +0100134Static Wheels
135~~~~~~~~~~~~~
136
137Cryptography ships statically-linked wheels for OS X and Windows, ensuring that
138these platforms can always use the most-recent OpenSSL, regardless of what is
139shipped by default on those platforms. As a result of various difficulties
140around Linux binary linking, Cryptography cannot do the same on Linux.
141
142However, you can build your own statically-linked wheels that will work on your
143own systems. This will allow you to continue to use relatively old Linux
144distributions (such as LTS releases), while making sure you have the most
145recent OpenSSL available to your Python programs.
146
147To do so, you should find yourself a machine that is as similar as possible to
148your target environment (e.g. your production environment): for example, spin
149up a new cloud server running your target Linux distribution. On this machine,
150install the Cryptography dependencies as mentioned in :ref:`build-on-linux`.
151Please also make sure you have `virtualenv`_ installed: this should be
152available from your system package manager.
153
Cory Benfield80781842015-10-07 15:07:57 +0100154Then, paste the following into a shell script. You'll need to populate the
155``OPENSSL_VERSION`` variable. To do that, visit `openssl.org`_ and find the
156latest non-FIPS release version number, then set the string appropriately. For
157example, for OpenSSL 1.0.2d, use ``OPENSSL_VERSION="1.0.2d"``.
Cory Benfield6d447282015-10-07 14:50:50 +0100158
159When this shell script is complete, you'll find a collection of wheel files in
160a directory called ``wheelhouse``. These wheels can be installed by a
161sufficiently-recent version of ``pip``. The Cryptography wheel in this
162directory contains a statically-linked OpenSSL binding, which ensures that you
163have access to the most-recent OpenSSL releases without corrupting your system
164dependencies.
165
166.. code-block:: console
167
168 set -e
169
Cory Benfield80781842015-10-07 15:07:57 +0100170 OPENSSL_VERSION="VERSIONGOESHERE"
Cory Benfield6d447282015-10-07 14:50:50 +0100171 CWD=$(pwd)
172
173 virtualenv env
174 . env/bin/activate
175 pip install -U setuptools
176 pip install -U wheel pip
Matt Thomasa187c972016-10-03 17:48:31 -0400177 curl -O https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz
Cory Benfield6d447282015-10-07 14:50:50 +0100178 tar xvf openssl-${OPENSSL_VERSION}.tar.gz
179 cd openssl-${OPENSSL_VERSION}
180 ./config no-shared no-ssl2 -fPIC --prefix=${CWD}/openssl
181 make && make install
182 cd ..
Cory Benfield09d1b472015-10-16 08:14:42 +0100183 CFLAGS="-I${CWD}/openssl/include" LDFLAGS="-L${CWD}/openssl/lib" pip wheel --no-use-wheel cryptography
Cory Benfield6d447282015-10-07 14:50:50 +0100184
Paul Kehrer451c8df2015-07-04 11:03:27 -0500185Building cryptography on OS X
186-----------------------------
187
Paul Kehrera17d5902016-03-20 22:29:17 -0400188.. note::
189
190 If installation gives a ``fatal error: 'openssl/aes.h' file not found``
191 see the :doc:`FAQ </faq>` for information about how to fix this issue.
192
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500193The wheel package on OS X is a statically linked build (as of 1.0.1) so for
Paul Kehrera17d5902016-03-20 22:29:17 -0400194users with pip 8 or above you only need one step:
Paul Kehrer451c8df2015-07-04 11:03:27 -0500195
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500196.. code-block:: console
skeuomorfbc26efb2014-01-29 08:31:47 +0200197
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500198 $ pip install cryptography
199
Akan Brown60cd5a62016-08-08 22:30:02 -0400200If you want to build cryptography yourself or are on an older OS X version,
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500201cryptography requires the presence of a C compiler, development headers, and
202the proper libraries. On OS X much of this is provided by Apple's Xcode
Paul Kehrerb29f4642015-12-31 23:27:25 -0600203development tools. To install the Xcode command line tools (on OS X 10.9+)
204open a terminal window and run:
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500205
206.. code-block:: console
207
208 $ xcode-select --install
209
210This will install a compiler (clang) along with (most of) the required
211development headers.
212
213You'll also need OpenSSL, which you can obtain from `Homebrew`_ or `MacPorts`_.
Paul Kehrer355174a2015-12-22 09:47:26 -0600214Cryptography does **not** support Apple's deprecated OpenSSL distribution.
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500215
216To build cryptography and dynamically link it:
Ayrx1ced5b82014-04-08 19:41:26 +0800217
218`Homebrew`_
skeuomorfbc26efb2014-01-29 08:31:47 +0200219
220.. code-block:: console
221
222 $ brew install openssl
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500223 $ env LDFLAGS="-L$(brew --prefix openssl)/lib" CFLAGS="-I$(brew --prefix openssl)/include" pip install cryptography
skeuomorfbc26efb2014-01-29 08:31:47 +0200224
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500225`MacPorts`_:
Kimmo Parviainen-Jalankoe01e0bf2014-03-19 18:57:09 +0200226
227.. code-block:: console
228
229 $ sudo port install openssl
Paul Kehrer1e071ac2015-09-05 16:30:25 -0500230 $ env LDFLAGS="-L/opt/local/lib" CFLAGS="-I/opt/local/include" pip install cryptography
231
232You can also build cryptography statically:
233
234`Homebrew`_
235
236.. code-block:: console
237
238 $ brew install openssl
239 $ 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
240
241`MacPorts`_:
242
243.. code-block:: console
244
245 $ sudo port install openssl
246 $ 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 +0200247
Paul Kehrerd4ea53b2015-12-31 19:48:32 -0600248If you need to rebuild ``cryptography`` for any reason be sure to clear the
249local `wheel cache`_.
250
Alex Gaynoreb50a2c2014-05-02 09:38:33 -0700251Building cryptography with conda
252--------------------------------
253
Alex Gaynore51236d2016-11-06 10:13:35 -0500254Because of a bug in conda, attempting to install cryptography out of the box
David Reide162e262014-05-07 16:21:00 -0700255will result in an error. This can be resolved by setting the library path
256environment variable for your platform.
David Reide43861d2014-05-07 16:19:08 -0700257
258On OS X:
Alex Gaynord8fc2572014-05-02 10:33:36 -0700259
260.. code-block:: console
261
262 $ env DYLD_LIBRARY_PATH="$HOME/anaconda/lib" pip install cryptography
263
David Reid18563e62014-05-07 16:20:09 -0700264and on Linux:
David Reide43861d2014-05-07 16:19:08 -0700265
266.. code-block:: console
267
268 $ env LD_LIBRARY_PATH="$HOME/anaconda/lib" pip install cryptography
269
Alex Gaynord8fc2572014-05-02 10:33:36 -0700270You will need to set this variable every time you start Python. For more
Alex Gaynorf65cba22014-05-02 10:40:57 -0700271information, consult `Greg Wilson's blog post`_ on the subject.
Alex Gaynoreb50a2c2014-05-02 09:38:33 -0700272
273
Alex Gaynor5ad6df92017-02-18 12:52:50 -0500274.. _`Homebrew`: https://brew.sh
Alex Gaynor3197ab52015-10-02 06:33:11 -0700275.. _`MacPorts`: https://www.macports.org
Paul Kehrer937aa472015-10-11 12:09:27 -0500276.. _`openssl-release`: https://jenkins.cryptography.io/job/openssl-release/
Alex Gaynor6422d832016-03-06 21:40:57 -0500277.. _`Greg Wilson's blog post`: https://software-carpentry.org/blog/2014/04/mr-biczo-was-right.html
Cory Benfieldba8f6382015-10-07 15:07:47 +0100278.. _virtualenv: https://virtualenv.pypa.io/en/latest/
Alex Gaynor769d5c62016-11-06 04:30:36 -0500279.. _openssl.org: https://www.openssl.org/source/
Paul Kehrerd4ea53b2015-12-31 19:48:32 -0600280.. _`wheel cache`: https://pip.pypa.io/en/stable/reference/pip_install/#caching