Installation

The installation procedure depends on the package you want the library in. PyCryptodome can be used as:

  1. a drop-in replacement for the old PyCrypto library. You install it with:

    pip install pycryptodome
    

    In this case, all modules are installed under the Crypto package. You can test everything is right with:

    python -m Crypto.SelfTest
    

    One must avoid having both PyCrypto and PyCryptodome installed at the same time, as they will interfere with each other.

    This option is therefore recommended only when you are sure that the whole application is deployed in a virtualenv.

  2. a library independent of the old PyCrypto. You install it with:

    pip install pycryptodomex
    

    You can test everything is right with:

    python -m Cryptodome.SelfTest
    

    In this case, all modules are installed under the Cryptodome package. PyCrypto and PyCryptodome can coexist.

The procedures below go a bit more in detail, by explaining how to setup the environment for compiling the C extensions for each OS, and how to install the GMP library.

All instructions to follow install PyCryptodome as the Cryptodome package (option #2). Change pycryptodomex to pycryptodome if you prefer option #1 (Crypto package).

Linux Ubuntu

For Python 2.x:

$ sudo apt-get install build-essential libgmp3-dev python-dev
$ pip install pycryptodomex
$ python -m Cryptodome.SelfTest

For Python 3.x:

$ sudo apt-get install build-essential libgmp3-dev python3-dev
$ pip install pycryptodomex
$ python3 -m Cryptodome.SelfTest

For PyPy:

$ sudo apt-get install build-essential libgmp3-dev pypy-dev
$ pip install pycryptodomex
$ pypy -m Cryptodome.SelfTest

Linux Fedora

For Python 2.x:

$ sudo yum install gcc gmp python-devel
$ pip install pycryptodomex
$ python -m Cryptodome.SelfTest

For Python 3.x:

$ sudo yum install gcc gmp python3-devel
$ pip install pycryptodomex
$ python3 -m Cryptodome.SelfTest

For PyPy:

$ sudo yum install gcc gmp pypy-devel
$ pip install pycryptodomex
$ pypy -m Cryptodome.SelfTest

Windows (pre-compiled)

  1. Install PyCryptodome as a wheel:

    > pip install pycryptodomex
    
  2. To make sure everything works fine, run the test suite:

    > python -m Cryptodome.SelfTest
    

Windows (from sources, Python 2.x, Python <=3.2)

Windows does not come with a C compiler like most Unix systems. The simplest way to compile the Pycryptodome extensions from source code is to install the minimum set of Visual Studio components freely made available by Microsoft.

  1. Run Python from the command line and note down its version and whether it is a 32 bit or a 64 bit application.

    For instance, if you see:

    Python 2.7.2+ ... [MSC v.1500 32 bit (Intel)] on win32
    

    you clearly have Python 2.7 and it is a 32 bit application.

  2. [Only once] In order to speed up asymmetric key algorithms like RSA, it is recommended to install the MPIR library (a fork of the popular GMP library, more suitable for the Windows environment). For convenience, I made available pre-compiled mpir.dll files to match the various types of Python one may have:

    Download the correct mpir.dll and drop it into the Python interpreter directory (for instance C:\Python34). Pycryptodome will automatically make use of it.

  3. [Only once] Install Virtual Clone Drive.

  4. [Only once] Download the ISO image of the `MS SDK for Windows 7 and . NET Framework 3.5 SP1`_. It contains the Visual C++ 2008 compiler.

    There are three ISO images available: you will need GRMSDK_EN_DVD.iso if your Windows OS is 32 bits or GRMSDKX_EN_DVD.iso if 64 bits.

    Mount the ISO with Virtual Clone Drive and install the C/C++ compilers and the redistributable only.

  5. If your Python is a 64 bit application, open a command prompt and perform the following steps:

    > cd "C:\Program Files\Microsoft SDKs\Windows\v7.0"
    > cmd /V:ON /K Bin\SetEnv.Cmd /x64 /release
    > set DISTUTILS_USE_SDK=1
    

    Replace /x64 with /x86 if your Python is a 32 bit application.

  6. Compile and install PyCryptodome:

    > pip install pycryptodomex --no-use-wheel
    
  7. To make sure everything work fine, run the test suite:

    > python -m Cryptodome.SelfTest
    

Windows (from sources, Python 3.3 and 3.4)

Windows does not come with a C compiler like most Unix systems. The simplest way to compile the Pycryptodome extensions from source code is to install the minimum set of Visual Studio components freely made available by Microsoft.

  1. Run Python from the command line and note down its version and whether it is a 32 bit or a 64 bit application.

    For instance, if you see:

    Python 2.7.2+ ... [MSC v.1500 32 bit (Intel)] on win32
    

    you clearly have Python 2.7 and it is a 32 bit application.

  2. [Only once] In order to speed up asymmetric key algorithms like RSA, it is recommended to install the MPIR library (a fork of the popular GMP library, more suitable for the Windows environment). For convenience, I made available pre-compiled mpir.dll files to match the various types of Python one may have:

    Download the correct mpir.dll and drop it into the Python interpreter directory (for instance C:\Python34). Pycryptodome will automatically make use of it.

  3. [Only once] Install Virtual Clone Drive.

  4. [Only once] Download the ISO image of the `MS SDK for Windows 7 and . NET Framework 4`_. It contains the Visual C++ 2010 compiler.

    There are three ISO images available: you will need GRMSDK_EN_DVD.iso if your Windows OS is 32 bits or GRMSDKX_EN_DVD.iso if 64 bits.

    Mount the ISO with Virtual Clone Drive and install the C/C++ compilers and the redistributable only.

  5. If your Python is a 64 bit application, open a command prompt and perform the following steps:

    > cd "C:\Program Files\Microsoft SDKs\Windows\v7.1"
    > cmd /V:ON /K Bin\SetEnv.Cmd /x64 /release
    > set DISTUTILS_USE_SDK=1
    

    Replace /x64 with /x86 if your Python is a 32 bit application.

  6. Compile and install PyCryptodome:

    > pip install pycryptodomex --no-use-wheel
    
  7. To make sure everything work fine, run the test suite:

    > python -m Cryptodome.SelfTest
    

Windows (from sources, Python 3.5 and newer)

Windows does not come with a C compiler like most Unix systems. The simplest way to compile the Pycryptodome extensions from source code is to install the minimum set of Visual Studio components freely made available by Microsoft.

  1. [Once only] Download MS Visual Studio 2015 (Community Edition) and install the C/C++ compilers and the redistributable only.

  2. Perform all steps from the section Windows (pre-compiled) but add the --no-use-wheel parameter when calling pip:

    > pip install pycryptodomex --no-use-wheel