macOS: pip install M2Crypto
Out of the box, trying to install M2Crypto on macOS will fail with one of two common scenarios on building.
Either you’ll get OpenSSL errors, in case you haven’t set up a newer version than the system one:
Error: Unable to find 'openssl/opensslv.h'
Or you’ll get a bunch of clang errors:
Error: invalid argument type 'void' to unary expression
All of this is addressed in the project installation page, which is however easy to miss since it isn’t mentioned anywhere in the PyPI readme, the first point of contact when a package doesn’t install correctly.
To build M2Crypto successfully you’ll need to:
- Install a newer version of OpenSSL along with Swig:
$ brew install openssl swig
- Set flags so the compiler can find the imports:
$ LDFLAGS="-L$(brew --prefix openssl)/lib" \ CFLAGS="-I$(brew --prefix openssl)/include" \ SWIG_FEATURES="-I$(brew --prefix openssl)/include"
- And then install install M2Crypto:
$ pip install m2crypto
If you’re mingling with crypto libraries, it’s a good guess you’ll need the newer OpenSSL again in the future, so it would be good to add and/or merge the above flags in your
.bashrc or similar.