Skip to content

Instantly share code, notes, and snippets.

@andrisasuke
Created May 2, 2017 10:12
Show Gist options
  • Star 31 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save andrisasuke/91eccace11366e626d14c5c249054e20 to your computer and use it in GitHub Desktop.
Save andrisasuke/91eccace11366e626d14c5c249054e20 to your computer and use it in GitHub Desktop.
python install m2crypto on Mac OS X
$> brew install openssl
$> brew install swig
$> env LDFLAGS="-L$(brew --prefix openssl)/lib" \
CFLAGS="-I$(brew --prefix openssl)/include" \
SWIG_FEATURES="-cpperraswarn -includeall -I$(brew --prefix openssl)/include" \
pip install m2crypto
@russau
Copy link

russau commented Aug 28, 2020

Hi @MdAbuNafeeIbnaZahid, unfortunately I didn't. I had to add a switch in my application to ignore m2crypto when I'm doing dev on my Mac, i.e.

try:
    from M2Crypto import SMIME, X509, BIO
    CRYPTO_LOADED = True
except ImportError:
    CRYPTO_LOADED = False

@bilalahmed54
Copy link

bilalahmed54 commented Jan 5, 2021

Getting the following error on Mac OS 11.1 (Big Sur):

/SDKs/MacOSX.sdk/usr/include -I/Library/Developer/CommandLineTools/usr/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory) -I/Library/Developer/CommandLineTools/usr/include/c++/v1 -I/usr/local/include -I/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -I/Library/Developer/CommandLineTools/usr/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory) -I/Users/admin/Desktop/BAY/projects/new_superset/superset/env/include -I/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8 -I/usr/include/openssl -includeall -modern -builtin -outdir /private/var/folders/1_/qxj8rn1x5y975c3w3sm47l1m0000gn/T/pip-install-webalskz/m2crypto_e8aad78ad6674b158348f6ca2270b5c2/M2Crypto -o SWIG/_m2crypto_wrap.c SWIG/_m2crypto.i Deprecated command line option: -modern. This option is now always on. /Library/Developer/CommandLineTools/usr/include/c++/v1/stdint.h:123: Error: Unknown SWIG preprocessor directive: include_next (if this is a block of target language code, delimit it with %{ and %}) error: command 'swig' failed with exit status 1

@mehdiAberkane
Copy link

Nice is work, thanks

@xiazhibin
Copy link

perfect!!

@bingwork
Copy link

bingwork commented Jun 9, 2021

it works for me, thanks.

@mrbungie
Copy link

mrbungie commented Nov 8, 2021

If you accidentally (or purposefully) you have another version of OpenSSL these are the correct commands:

brew install openssl@1.1

env LDFLAGS="-L$(brew --prefix openssl@1.1)/lib" \
CFLAGS="-I$(brew --prefix openssl@1.1)/include" \
SWIG_FEATURES="-cpperraswarn -includeall -I$(brew --prefix openssl@1.1)/include" \
pip install m2crypto

@laggardkernel
Copy link

 include/sys/_types/_int8_t.h:30: Error: Syntax error in input(1).
    error: command 'swig' failed with exit status 1

You need to make sure a real gcc (not /usr/bin/gcc, which is clang) installed. Otherwise it uses clang to build the package.

@ivanporras
Copy link

_m2crypto.so' (mach-o file, but is an incompatible architecture (have (x86_64), need (arm64e)))

Any solution?

@mambelli
Copy link

Worked for me (Intel Mac Ventura, openssl@3). I set the environment and to get the right Python I used python3 -m pip install m2crypto

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment