Installing Cryptography via Pip with MacPorts or Homebrew

If you have tried installing / updating pyOpenSSL to version 0.14 you may have run into an issue when it tries to install the required package cryptography. The specific error I encountered was:

raise ffiplatform.VerificationError(error)
cffi.ffiplatform.VerificationError: importing '/private/tmp/pip_build_root/cryptography/cryptography/hazmat/bindings/__pycache__/': dlopen(/private/tmp/pip_build_root/cryptography/cryptography/hazmat/bindings/__pycache__/, 2): Symbol not found: _CRYPTO_malloc_debug_init
Referenced from: /private/tmp/pip_build_root/cryptography/cryptography/hazmat/bindings/__pycache__/
Expected in: flat namespace
in /private/tmp/pip_build_root/cryptography/cryptography/hazmat/bindings/__pycache__/

view raw

hosted with ❤ by GitHub

To get around this, you’ll need to set some environment variables before installing cryptography:

# install via MacPorts
sudo port install openssl
sudo env ARCHFLAGS="-arch x86_64" LDFLAGS="-L/opt/local/lib" CFLAGS="-I/opt/local/include" pip install cryptography
# install via Homebrew
brew install openssl
env ARCHFLAGS="-arch x86_64" LDFLAGS="-L/usr/local/opt/openssl/lib" CFLAGS="-I/usr/local/opt/openssl/include" pip install cryptography

view raw

hosted with ❤ by GitHub

A pull request has been opened to add this to the documentation but as of this writing it has not yet been merged.

10 thoughts on “Installing Cryptography via Pip with MacPorts or Homebrew”

  1. Good day !

    I will be very happy, if you told me: that i doing wrong ?

    File “C:\Python27\lib\cryptography\hazmat\bindings\openssl\”, line 1
    3, in
    from cryptography.hazmat.bindings._openssl import ffi, lib
    ImportError: No module named _openssl

    P.S. I think. that file: is absent on my HDD

    With best regrets!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s