Installing Cryptography on an Apple Silicon M1 Mac

This issue is due to a mismatch between the libffi header version and the version of libffi the dynamic linker finds. In general it appears users encountering this problem have homebrew libffi installed and have a Python built against that in some fashion.

When this happens cffi (a cryptography dependency) compiles, but fails at runtime raising this error. This should be fixable by passing the right path as a linker argument. To reinstall cffi you should pip uninstall cffi followed by

LDFLAGS=-L$(brew --prefix libffi)/lib CFLAGS=-I$(brew --prefix libffi)/include pip install cffi --no-binary :all:

This is an ugly workaround, but will get you past this hurdle for now.

Update: I’ve uploaded arm64 wheels for macOS so the below compilation is no longer required if your pip is up-to-date. However, if, for some reason you wish to compile it yourself:

LDFLAGS="-L$(brew --prefix [email protected])/lib" CFLAGS="-I$(brew --prefix [email protected])/include" pip install cryptography

Update 2023: As of 2023 there are wheels for cffi and cryptography for Apple Silicon. If you are still seeing this type of error, there are a few likely culprits:

  1. Your pip is out of date. Update to latest! You can (and should) do all of this in a virtual environment.
  2. You are attempting to install an older version of cryptography. Any version >= 3.4.6 has an apple silicon wheel (either arm64 or universal2), but we only support the latest release so always update.
  3. You are attempting to install an older version of cffi. cffi cannot use abi3 so new wheels must be uploaded for each major Python release. If you’re attempting to run an older cffi on a newer Python then a wheel may not be available and you’ll need to compile.

Leave a Comment