Alex Gaynor | 84d5c6b | 2014-02-02 10:12:34 -0800 | [diff] [blame] | 1 | Installation |
| 2 | ============ |
skeuomorf | bc26efb | 2014-01-29 08:31:47 +0200 | [diff] [blame] | 3 | |
| 4 | You can install ``cryptography`` with ``pip``: |
| 5 | |
| 6 | .. code-block:: console |
| 7 | |
| 8 | $ pip install cryptography |
| 9 | |
Alex Stapleton | b468417 | 2014-03-15 18:02:13 +0000 | [diff] [blame] | 10 | Supported platforms |
| 11 | ------------------- |
| 12 | |
Alex Gaynor | a26c13a | 2015-09-25 17:52:06 -0400 | [diff] [blame] | 13 | Currently we test ``cryptography`` on Python 2.6, 2.7, 3.3, 3.4, 3.5, and PyPy |
| 14 | 2.6+ on these operating systems. |
Alex Stapleton | b468417 | 2014-03-15 18:02:13 +0000 | [diff] [blame] | 15 | |
Alex Gaynor | 1252dec | 2016-06-18 11:11:57 -0400 | [diff] [blame] | 16 | * x86-64 CentOS 7.x, 6.4 |
Paul Kehrer | bd88ee6 | 2015-02-20 10:38:31 -0600 | [diff] [blame] | 17 | * x86-64 FreeBSD 10 |
Paul Kehrer | da74298 | 2015-10-01 21:10:26 -0500 | [diff] [blame] | 18 | * 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 Stapleton | b468417 | 2014-03-15 18:02:13 +0000 | [diff] [blame] | 23 | |
Paul Kehrer | 56b360a | 2015-12-31 19:59:25 -0600 | [diff] [blame] | 24 | .. 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 Kehrer | fb8dcdb | 2014-04-20 19:25:18 -0500 | [diff] [blame] | 28 | We test compiling with ``clang`` as well as ``gcc`` and use the following |
| 29 | OpenSSL releases: |
| 30 | |
Paul Kehrer | fb8dcdb | 2014-04-20 19:25:18 -0500 | [diff] [blame] | 31 | * ``OpenSSL 1.0.0-fips`` (``RHEL/CentOS 6.4``) |
| 32 | * ``OpenSSL 1.0.1`` |
Paul Kehrer | e683dee | 2014-08-09 08:15:23 -1000 | [diff] [blame] | 33 | * ``OpenSSL 1.0.1e-fips`` (``RHEL/CentOS 7``) |
Paul Kehrer | 96a0827 | 2015-02-21 18:37:38 -0600 | [diff] [blame] | 34 | * ``OpenSSL 1.0.1j-freebsd`` |
Paul Kehrer | da74298 | 2015-10-01 21:10:26 -0500 | [diff] [blame] | 35 | * ``OpenSSL 1.0.1f`` |
| 36 | * ``OpenSSL 1.0.2-latest`` |
Paul Kehrer | 07ea3cd | 2016-08-26 21:48:24 +0800 | [diff] [blame] | 37 | * ``OpenSSL 1.1.0`` |
Paul Kehrer | fb8dcdb | 2014-04-20 19:25:18 -0500 | [diff] [blame] | 38 | |
Paul Kehrer | 56b360a | 2015-12-31 19:59:25 -0600 | [diff] [blame] | 39 | .. warning:: |
Alex Gaynor | 1252dec | 2016-06-18 11:11:57 -0400 | [diff] [blame] | 40 | OpenSSL 1.0.0 is no longer supported by the OpenSSL project. Cryptography |
Alex Gaynor | 3b83fc2 | 2016-08-26 22:11:50 -0400 | [diff] [blame] | 41 | will drop support for it in the next release. |
Paul Kehrer | 56b360a | 2015-12-31 19:59:25 -0600 | [diff] [blame] | 42 | |
Nick Badger | 63bbf18 | 2016-09-03 10:10:36 -0700 | [diff] [blame] | 43 | Building cryptography on Windows |
| 44 | -------------------------------- |
Alex Gaynor | 84d5c6b | 2014-02-02 10:12:34 -0800 | [diff] [blame] | 45 | |
Paul Kehrer | 156360a | 2014-06-30 12:14:01 -0600 | [diff] [blame] | 46 | The wheel package on Windows is a statically linked build (as of 0.5) so all |
Nick Badger | 63bbf18 | 2016-09-03 10:10:36 -0700 | [diff] [blame] | 47 | dependencies are included. To install ``cryptography``, you will typically |
| 48 | just run |
Paul Kehrer | 156360a | 2014-06-30 12:14:01 -0600 | [diff] [blame] | 49 | |
| 50 | .. code-block:: console |
| 51 | |
| 52 | $ pip install cryptography |
| 53 | |
| 54 | If you prefer to compile it yourself you'll need to have OpenSSL installed. |
Paul Kehrer | 6608b7e | 2015-07-24 21:52:17 +0100 | [diff] [blame] | 55 | You can compile OpenSSL yourself as well or use the binaries we build for our |
Paul Kehrer | 937aa47 | 2015-10-11 12:09:27 -0500 | [diff] [blame] | 56 | release infrastructure (`openssl-release`_). Be sure to download the proper |
| 57 | version for your architecture and Python (2010 works for Python 2.6, 2.7, 3.3, |
| 58 | and 3.4 while 2015 is required for 3.5). Wherever you place your copy |
Paul Kehrer | 6608b7e | 2015-07-24 21:52:17 +0100 | [diff] [blame] | 59 | of OpenSSL you'll need to set the ``LIB`` and ``INCLUDE`` environment variables |
| 60 | to include the proper locations. For example: |
skeuomorf | bc26efb | 2014-01-29 08:31:47 +0200 | [diff] [blame] | 61 | |
skeuomorf | b0293bf | 2014-01-29 21:41:02 +0200 | [diff] [blame] | 62 | .. code-block:: console |
| 63 | |
| 64 | C:\> \path\to\vcvarsall.bat x86_amd64 |
Paul Kehrer | 6608b7e | 2015-07-24 21:52:17 +0100 | [diff] [blame] | 65 | C:\> set LIB=C:\OpenSSL-win64\lib;%LIB% |
| 66 | C:\> set INCLUDE=C:\OpenSSL-win64\include;%INCLUDE% |
Paul Kehrer | 2a39f7f | 2014-07-02 22:56:01 -0500 | [diff] [blame] | 67 | C:\> pip install cryptography |
| 68 | |
Paul Kehrer | d4ea53b | 2015-12-31 19:48:32 -0600 | [diff] [blame] | 69 | If you need to rebuild ``cryptography`` for any reason be sure to clear the |
| 70 | local `wheel cache`_. |
skeuomorf | bc26efb | 2014-01-29 08:31:47 +0200 | [diff] [blame] | 71 | |
Cory Benfield | 6d44728 | 2015-10-07 14:50:50 +0100 | [diff] [blame] | 72 | .. _build-on-linux: |
| 73 | |
Chris Glass | 2e15c7f | 2014-02-13 19:10:10 +0100 | [diff] [blame] | 74 | Building cryptography on Linux |
| 75 | ------------------------------ |
Chris Glass | 87c4edb | 2014-02-13 09:34:21 +0100 | [diff] [blame] | 76 | |
Chris Glass | 2e15c7f | 2014-02-13 19:10:10 +0100 | [diff] [blame] | 77 | ``cryptography`` should build very easily on Linux provided you have a C |
Alex Gaynor | 4992384 | 2014-02-13 10:32:56 -0800 | [diff] [blame] | 78 | compiler, headers for Python (if you're not using ``pypy``), and headers for |
| 79 | the OpenSSL and ``libffi`` libraries available on your system. |
Chris Glass | 87c4edb | 2014-02-13 09:34:21 +0100 | [diff] [blame] | 80 | |
Ayrx | d9702f9 | 2014-02-15 23:57:13 +0800 | [diff] [blame] | 81 | For Debian and Ubuntu, the following command will ensure that the required |
Chris Glass | f82d94f | 2014-02-13 11:46:49 +0100 | [diff] [blame] | 82 | dependencies are installed: |
Chris Glass | 87c4edb | 2014-02-13 09:34:21 +0100 | [diff] [blame] | 83 | |
| 84 | .. code-block:: console |
| 85 | |
Alex Gaynor | 4992384 | 2014-02-13 10:32:56 -0800 | [diff] [blame] | 86 | $ sudo apt-get install build-essential libssl-dev libffi-dev python-dev |
Chris Glass | 87c4edb | 2014-02-13 09:34:21 +0100 | [diff] [blame] | 87 | |
Ayrx | d9702f9 | 2014-02-15 23:57:13 +0800 | [diff] [blame] | 88 | For Fedora and RHEL-derivatives, the following command will ensure that the |
| 89 | required dependencies are installed: |
Ayrx | a674c6b | 2014-02-15 21:24:23 +0800 | [diff] [blame] | 90 | |
| 91 | .. code-block:: console |
| 92 | |
| 93 | $ sudo yum install gcc libffi-devel python-devel openssl-devel |
| 94 | |
Chris Glass | 87c4edb | 2014-02-13 09:34:21 +0100 | [diff] [blame] | 95 | You should now be able to build and install cryptography with the usual |
| 96 | |
| 97 | .. code-block:: console |
| 98 | |
Alex Gaynor | 4992384 | 2014-02-13 10:32:56 -0800 | [diff] [blame] | 99 | $ pip install cryptography |
Chris Glass | 87c4edb | 2014-02-13 09:34:21 +0100 | [diff] [blame] | 100 | |
Alex Gaynor | eb50a2c | 2014-05-02 09:38:33 -0700 | [diff] [blame] | 101 | |
Chris Glass | 2e15c7f | 2014-02-13 19:10:10 +0100 | [diff] [blame] | 102 | Using your own OpenSSL on Linux |
| 103 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
skeuomorf | bc26efb | 2014-01-29 08:31:47 +0200 | [diff] [blame] | 104 | |
| 105 | Python links to OpenSSL for its own purposes and this can sometimes cause |
| 106 | problems when you wish to use a different version of OpenSSL with cryptography. |
| 107 | If you want to use cryptography with your own build of OpenSSL you will need to |
| 108 | make sure that the build is configured correctly so that your version of |
| 109 | OpenSSL doesn't conflict with Python's. |
| 110 | |
| 111 | The options you need to add allow the linker to identify every symbol correctly |
| 112 | even when multiple versions of the library are linked into the same program. If |
| 113 | you are using your distribution's source packages these will probably be |
| 114 | patched in for you already, otherwise you'll need to use options something like |
| 115 | this when configuring OpenSSL: |
| 116 | |
| 117 | .. code-block:: console |
| 118 | |
| 119 | $ ./config -Wl,--version-script=openssl.ld -Wl,-Bsymbolic-functions -fPIC shared |
| 120 | |
| 121 | You'll also need to generate your own ``openssl.ld`` file. For example:: |
| 122 | |
| 123 | OPENSSL_1.0.1F_CUSTOM { |
| 124 | global: |
| 125 | *; |
| 126 | }; |
| 127 | |
| 128 | You should replace the version string on the first line as appropriate for your |
| 129 | build. |
| 130 | |
Cory Benfield | 6d44728 | 2015-10-07 14:50:50 +0100 | [diff] [blame] | 131 | Static Wheels |
| 132 | ~~~~~~~~~~~~~ |
| 133 | |
| 134 | Cryptography ships statically-linked wheels for OS X and Windows, ensuring that |
| 135 | these platforms can always use the most-recent OpenSSL, regardless of what is |
| 136 | shipped by default on those platforms. As a result of various difficulties |
| 137 | around Linux binary linking, Cryptography cannot do the same on Linux. |
| 138 | |
| 139 | However, you can build your own statically-linked wheels that will work on your |
| 140 | own systems. This will allow you to continue to use relatively old Linux |
| 141 | distributions (such as LTS releases), while making sure you have the most |
| 142 | recent OpenSSL available to your Python programs. |
| 143 | |
| 144 | To do so, you should find yourself a machine that is as similar as possible to |
| 145 | your target environment (e.g. your production environment): for example, spin |
| 146 | up a new cloud server running your target Linux distribution. On this machine, |
| 147 | install the Cryptography dependencies as mentioned in :ref:`build-on-linux`. |
| 148 | Please also make sure you have `virtualenv`_ installed: this should be |
| 149 | available from your system package manager. |
| 150 | |
Cory Benfield | 8078184 | 2015-10-07 15:07:57 +0100 | [diff] [blame] | 151 | Then, paste the following into a shell script. You'll need to populate the |
| 152 | ``OPENSSL_VERSION`` variable. To do that, visit `openssl.org`_ and find the |
| 153 | latest non-FIPS release version number, then set the string appropriately. For |
| 154 | example, for OpenSSL 1.0.2d, use ``OPENSSL_VERSION="1.0.2d"``. |
Cory Benfield | 6d44728 | 2015-10-07 14:50:50 +0100 | [diff] [blame] | 155 | |
| 156 | When this shell script is complete, you'll find a collection of wheel files in |
| 157 | a directory called ``wheelhouse``. These wheels can be installed by a |
| 158 | sufficiently-recent version of ``pip``. The Cryptography wheel in this |
| 159 | directory contains a statically-linked OpenSSL binding, which ensures that you |
| 160 | have access to the most-recent OpenSSL releases without corrupting your system |
| 161 | dependencies. |
| 162 | |
| 163 | .. code-block:: console |
| 164 | |
| 165 | set -e |
| 166 | |
Cory Benfield | 8078184 | 2015-10-07 15:07:57 +0100 | [diff] [blame] | 167 | OPENSSL_VERSION="VERSIONGOESHERE" |
Cory Benfield | 6d44728 | 2015-10-07 14:50:50 +0100 | [diff] [blame] | 168 | CWD=$(pwd) |
| 169 | |
| 170 | virtualenv env |
| 171 | . env/bin/activate |
| 172 | pip install -U setuptools |
| 173 | pip install -U wheel pip |
Matt Thomas | a187c97 | 2016-10-03 17:48:31 -0400 | [diff] [blame] | 174 | curl -O https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz |
Cory Benfield | 6d44728 | 2015-10-07 14:50:50 +0100 | [diff] [blame] | 175 | tar xvf openssl-${OPENSSL_VERSION}.tar.gz |
| 176 | cd openssl-${OPENSSL_VERSION} |
| 177 | ./config no-shared no-ssl2 -fPIC --prefix=${CWD}/openssl |
| 178 | make && make install |
| 179 | cd .. |
Cory Benfield | 09d1b47 | 2015-10-16 08:14:42 +0100 | [diff] [blame] | 180 | CFLAGS="-I${CWD}/openssl/include" LDFLAGS="-L${CWD}/openssl/lib" pip wheel --no-use-wheel cryptography |
Cory Benfield | 6d44728 | 2015-10-07 14:50:50 +0100 | [diff] [blame] | 181 | |
Paul Kehrer | 451c8df | 2015-07-04 11:03:27 -0500 | [diff] [blame] | 182 | Building cryptography on OS X |
| 183 | ----------------------------- |
| 184 | |
Paul Kehrer | a17d590 | 2016-03-20 22:29:17 -0400 | [diff] [blame] | 185 | .. note:: |
| 186 | |
| 187 | If installation gives a ``fatal error: 'openssl/aes.h' file not found`` |
| 188 | see the :doc:`FAQ </faq>` for information about how to fix this issue. |
| 189 | |
Paul Kehrer | 1e071ac | 2015-09-05 16:30:25 -0500 | [diff] [blame] | 190 | The wheel package on OS X is a statically linked build (as of 1.0.1) so for |
Paul Kehrer | a17d590 | 2016-03-20 22:29:17 -0400 | [diff] [blame] | 191 | users with pip 8 or above you only need one step: |
Paul Kehrer | 451c8df | 2015-07-04 11:03:27 -0500 | [diff] [blame] | 192 | |
Paul Kehrer | 1e071ac | 2015-09-05 16:30:25 -0500 | [diff] [blame] | 193 | .. code-block:: console |
skeuomorf | bc26efb | 2014-01-29 08:31:47 +0200 | [diff] [blame] | 194 | |
Paul Kehrer | 1e071ac | 2015-09-05 16:30:25 -0500 | [diff] [blame] | 195 | $ pip install cryptography |
| 196 | |
Akan Brown | 60cd5a6 | 2016-08-08 22:30:02 -0400 | [diff] [blame] | 197 | If you want to build cryptography yourself or are on an older OS X version, |
Paul Kehrer | 1e071ac | 2015-09-05 16:30:25 -0500 | [diff] [blame] | 198 | cryptography requires the presence of a C compiler, development headers, and |
| 199 | the proper libraries. On OS X much of this is provided by Apple's Xcode |
Paul Kehrer | b29f464 | 2015-12-31 23:27:25 -0600 | [diff] [blame] | 200 | development tools. To install the Xcode command line tools (on OS X 10.9+) |
| 201 | open a terminal window and run: |
Paul Kehrer | 1e071ac | 2015-09-05 16:30:25 -0500 | [diff] [blame] | 202 | |
| 203 | .. code-block:: console |
| 204 | |
| 205 | $ xcode-select --install |
| 206 | |
| 207 | This will install a compiler (clang) along with (most of) the required |
| 208 | development headers. |
| 209 | |
| 210 | You'll also need OpenSSL, which you can obtain from `Homebrew`_ or `MacPorts`_. |
Paul Kehrer | 355174a | 2015-12-22 09:47:26 -0600 | [diff] [blame] | 211 | Cryptography does **not** support Apple's deprecated OpenSSL distribution. |
Paul Kehrer | 1e071ac | 2015-09-05 16:30:25 -0500 | [diff] [blame] | 212 | |
| 213 | To build cryptography and dynamically link it: |
Ayrx | 1ced5b8 | 2014-04-08 19:41:26 +0800 | [diff] [blame] | 214 | |
| 215 | `Homebrew`_ |
skeuomorf | bc26efb | 2014-01-29 08:31:47 +0200 | [diff] [blame] | 216 | |
| 217 | .. code-block:: console |
| 218 | |
| 219 | $ brew install openssl |
Paul Kehrer | 1e071ac | 2015-09-05 16:30:25 -0500 | [diff] [blame] | 220 | $ env LDFLAGS="-L$(brew --prefix openssl)/lib" CFLAGS="-I$(brew --prefix openssl)/include" pip install cryptography |
skeuomorf | bc26efb | 2014-01-29 08:31:47 +0200 | [diff] [blame] | 221 | |
Paul Kehrer | 1e071ac | 2015-09-05 16:30:25 -0500 | [diff] [blame] | 222 | `MacPorts`_: |
Kimmo Parviainen-Jalanko | e01e0bf | 2014-03-19 18:57:09 +0200 | [diff] [blame] | 223 | |
| 224 | .. code-block:: console |
| 225 | |
| 226 | $ sudo port install openssl |
Paul Kehrer | 1e071ac | 2015-09-05 16:30:25 -0500 | [diff] [blame] | 227 | $ env LDFLAGS="-L/opt/local/lib" CFLAGS="-I/opt/local/include" pip install cryptography |
| 228 | |
| 229 | You can also build cryptography statically: |
| 230 | |
| 231 | `Homebrew`_ |
| 232 | |
| 233 | .. code-block:: console |
| 234 | |
| 235 | $ brew install openssl |
| 236 | $ 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 |
| 237 | |
| 238 | `MacPorts`_: |
| 239 | |
| 240 | .. code-block:: console |
| 241 | |
| 242 | $ sudo port install openssl |
| 243 | $ 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 |
skeuomorf | bc26efb | 2014-01-29 08:31:47 +0200 | [diff] [blame] | 244 | |
Paul Kehrer | d4ea53b | 2015-12-31 19:48:32 -0600 | [diff] [blame] | 245 | If you need to rebuild ``cryptography`` for any reason be sure to clear the |
| 246 | local `wheel cache`_. |
| 247 | |
Alex Gaynor | eb50a2c | 2014-05-02 09:38:33 -0700 | [diff] [blame] | 248 | Building cryptography with conda |
| 249 | -------------------------------- |
| 250 | |
Alex Gaynor | d694838 | 2014-05-02 14:10:14 -0700 | [diff] [blame] | 251 | Because of a `bug in conda`_, attempting to install cryptography out of the box |
David Reid | e162e26 | 2014-05-07 16:21:00 -0700 | [diff] [blame] | 252 | will result in an error. This can be resolved by setting the library path |
| 253 | environment variable for your platform. |
David Reid | e43861d | 2014-05-07 16:19:08 -0700 | [diff] [blame] | 254 | |
| 255 | On OS X: |
Alex Gaynor | d8fc257 | 2014-05-02 10:33:36 -0700 | [diff] [blame] | 256 | |
| 257 | .. code-block:: console |
| 258 | |
| 259 | $ env DYLD_LIBRARY_PATH="$HOME/anaconda/lib" pip install cryptography |
| 260 | |
David Reid | 18563e6 | 2014-05-07 16:20:09 -0700 | [diff] [blame] | 261 | and on Linux: |
David Reid | e43861d | 2014-05-07 16:19:08 -0700 | [diff] [blame] | 262 | |
| 263 | .. code-block:: console |
| 264 | |
| 265 | $ env LD_LIBRARY_PATH="$HOME/anaconda/lib" pip install cryptography |
| 266 | |
Alex Gaynor | d8fc257 | 2014-05-02 10:33:36 -0700 | [diff] [blame] | 267 | You will need to set this variable every time you start Python. For more |
Alex Gaynor | f65cba2 | 2014-05-02 10:40:57 -0700 | [diff] [blame] | 268 | information, consult `Greg Wilson's blog post`_ on the subject. |
Alex Gaynor | eb50a2c | 2014-05-02 09:38:33 -0700 | [diff] [blame] | 269 | |
| 270 | |
skeuomorf | bc26efb | 2014-01-29 08:31:47 +0200 | [diff] [blame] | 271 | .. _`Homebrew`: http://brew.sh |
Alex Gaynor | 3197ab5 | 2015-10-02 06:33:11 -0700 | [diff] [blame] | 272 | .. _`MacPorts`: https://www.macports.org |
Paul Kehrer | 937aa47 | 2015-10-11 12:09:27 -0500 | [diff] [blame] | 273 | .. _`openssl-release`: https://jenkins.cryptography.io/job/openssl-release/ |
Alex Gaynor | d694838 | 2014-05-02 14:10:14 -0700 | [diff] [blame] | 274 | .. _`bug in conda`: https://github.com/conda/conda-recipes/issues/110 |
Alex Gaynor | 6422d83 | 2016-03-06 21:40:57 -0500 | [diff] [blame] | 275 | .. _`Greg Wilson's blog post`: https://software-carpentry.org/blog/2014/04/mr-biczo-was-right.html |
Cory Benfield | ba8f638 | 2015-10-07 15:07:47 +0100 | [diff] [blame] | 276 | .. _virtualenv: https://virtualenv.pypa.io/en/latest/ |
Alex Gaynor | 769d5c6 | 2016-11-06 04:30:36 -0500 | [diff] [blame^] | 277 | .. _openssl.org: https://www.openssl.org/source/ |
Paul Kehrer | d4ea53b | 2015-12-31 19:48:32 -0600 | [diff] [blame] | 278 | .. _`wheel cache`: https://pip.pypa.io/en/stable/reference/pip_install/#caching |