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.