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 | |
skeuomorf | bc26efb | 2014-01-29 08:31:47 +0200 | [diff] [blame] | 10 | On Windows |
| 11 | ---------- |
Alex Gaynor | 84d5c6b | 2014-02-02 10:12:34 -0800 | [diff] [blame] | 12 | |
skeuomorf | b0293bf | 2014-01-29 21:41:02 +0200 | [diff] [blame] | 13 | If you're on Windows you'll need to make sure you have OpenSSL installed. |
| 14 | There are `pre-compiled binaries`_ available. If your installation is in |
| 15 | an unusual location set the ``LIB`` and ``INCLUDE`` environment variables |
| 16 | to include the corresponding locations. For example: |
skeuomorf | bc26efb | 2014-01-29 08:31:47 +0200 | [diff] [blame] | 17 | |
skeuomorf | b0293bf | 2014-01-29 21:41:02 +0200 | [diff] [blame] | 18 | .. code-block:: console |
| 19 | |
| 20 | C:\> \path\to\vcvarsall.bat x86_amd64 |
| 21 | C:\> set LIB=C:\OpenSSL-1.0.1f-64bit\lib;%LIB% |
| 22 | C:\> set INCLUDE=C:\OpenSSL-1.0.1f-64bit\include;%INCLUDE% |
| 23 | C:\> pip install cryptography |
skeuomorf | bc26efb | 2014-01-29 08:31:47 +0200 | [diff] [blame] | 24 | |
Chris Glass | 2e15c7f | 2014-02-13 19:10:10 +0100 | [diff] [blame] | 25 | Building cryptography on Linux |
| 26 | ------------------------------ |
Chris Glass | 87c4edb | 2014-02-13 09:34:21 +0100 | [diff] [blame] | 27 | |
Chris Glass | 2e15c7f | 2014-02-13 19:10:10 +0100 | [diff] [blame] | 28 | ``cryptography`` should build very easily on Linux provided you have a C |
Alex Gaynor | 4992384 | 2014-02-13 10:32:56 -0800 | [diff] [blame] | 29 | compiler, headers for Python (if you're not using ``pypy``), and headers for |
| 30 | the OpenSSL and ``libffi`` libraries available on your system. |
Chris Glass | 87c4edb | 2014-02-13 09:34:21 +0100 | [diff] [blame] | 31 | |
Chris Glass | f82d94f | 2014-02-13 11:46:49 +0100 | [diff] [blame] | 32 | Debian and Ubuntu systems |
Chris Glass | 2e15c7f | 2014-02-13 19:10:10 +0100 | [diff] [blame] | 33 | ~~~~~~~~~~~~~~~~~~~~~~~~~ |
Chris Glass | f82d94f | 2014-02-13 11:46:49 +0100 | [diff] [blame] | 34 | |
| 35 | For Debian and Ubuntu, the following command line will ensure the required |
| 36 | dependencies are installed: |
Chris Glass | 87c4edb | 2014-02-13 09:34:21 +0100 | [diff] [blame] | 37 | |
| 38 | .. code-block:: console |
| 39 | |
Alex Gaynor | 4992384 | 2014-02-13 10:32:56 -0800 | [diff] [blame] | 40 | $ sudo apt-get install build-essential libssl-dev libffi-dev python-dev |
Chris Glass | 87c4edb | 2014-02-13 09:34:21 +0100 | [diff] [blame] | 41 | |
| 42 | You should now be able to build and install cryptography with the usual |
| 43 | |
| 44 | .. code-block:: console |
| 45 | |
Alex Gaynor | 4992384 | 2014-02-13 10:32:56 -0800 | [diff] [blame] | 46 | $ pip install cryptography |
Chris Glass | 87c4edb | 2014-02-13 09:34:21 +0100 | [diff] [blame] | 47 | |
Chris Glass | 2e15c7f | 2014-02-13 19:10:10 +0100 | [diff] [blame] | 48 | Using your own OpenSSL on Linux |
| 49 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
skeuomorf | bc26efb | 2014-01-29 08:31:47 +0200 | [diff] [blame] | 50 | |
| 51 | Python links to OpenSSL for its own purposes and this can sometimes cause |
| 52 | problems when you wish to use a different version of OpenSSL with cryptography. |
| 53 | If you want to use cryptography with your own build of OpenSSL you will need to |
| 54 | make sure that the build is configured correctly so that your version of |
| 55 | OpenSSL doesn't conflict with Python's. |
| 56 | |
| 57 | The options you need to add allow the linker to identify every symbol correctly |
| 58 | even when multiple versions of the library are linked into the same program. If |
| 59 | you are using your distribution's source packages these will probably be |
| 60 | patched in for you already, otherwise you'll need to use options something like |
| 61 | this when configuring OpenSSL: |
| 62 | |
| 63 | .. code-block:: console |
| 64 | |
| 65 | $ ./config -Wl,--version-script=openssl.ld -Wl,-Bsymbolic-functions -fPIC shared |
| 66 | |
| 67 | You'll also need to generate your own ``openssl.ld`` file. For example:: |
| 68 | |
| 69 | OPENSSL_1.0.1F_CUSTOM { |
| 70 | global: |
| 71 | *; |
| 72 | }; |
| 73 | |
| 74 | You should replace the version string on the first line as appropriate for your |
| 75 | build. |
| 76 | |
| 77 | Using your own OpenSSL on OS X |
| 78 | ------------------------------ |
| 79 | |
| 80 | To link cryptography against a custom version of OpenSSL you'll need to set |
| 81 | ``ARCHFLAGS``, ``LDFLAGS``, and ``CFLAGS``. OpenSSL can be installed via |
| 82 | `Homebrew`_: |
| 83 | |
| 84 | .. code-block:: console |
| 85 | |
| 86 | $ brew install openssl |
| 87 | |
| 88 | Then install cryptography linking against the brewed version: |
| 89 | |
| 90 | .. code-block:: console |
| 91 | |
| 92 | $ env ARCHFLAGS="-arch x86_64" LDFLAGS="-L/usr/local/opt/openssl/lib" CFLAGS="-I/usr/local/opt/openssl/include" pip install cryptography |
| 93 | |
| 94 | |
| 95 | .. _`Homebrew`: http://brew.sh |
| 96 | .. _`pre-compiled binaries`: https://www.openssl.org/related/binaries.html |