Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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
Copy link

vsgobbi commented Mar 21, 2019

wow! great solution! worked as a charm

Copy link

csailer commented Jun 27, 2019


Copy link

braianj commented Jul 22, 2019

error here:

    cc -bundle -undefined dynamic_lookup -Wl,-F. -L/usr/local/opt/openssl/lib -I/usr/local/opt/openssl/include build/temp.macosx-10.14-intel-2.7/SWIG/_m2crypto_wrap.o -lssl -lcrypto -o build/lib.macosx-10.14-intel-2.7/M2Crypto/
    running install_lib
    creating /Library/Python/2.7/site-packages/M2Crypto
    error: could not create '/Library/Python/2.7/site-packages/M2Crypto': Permission denied
ERROR: Command "/usr/bin/python -u -c 'import setuptools, tokenize;__file__='"'"'/private/var/folders/p6/48f1pg5d4f5g88k2tnwtbbp00000gn/T/pip-install-MyOI96/m2crypto/'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);'"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/p6/48f1pg5d4f5g88k2tnwtbbp00000gn/T/pip-record-JTVVyl/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/p6/48f1pg5d4f5g88k2tnwtbbp00000gn/T/pip-install-MyOI96/m2crypto/

Any idea?

Copy link

billjyc commented May 12, 2020

thank you

Copy link

russau commented Jun 13, 2020

I hit some errors in Catalina. Firstly, the location of usr/include has changed. I followed some suggestions from this article.

I'm picking up the includes okay now. But hitting a compile error:

/Applications/ Error: Syntax error in input(1).
    error: command 'swig' failed with exit status 1

I'm stuck here and would really really appreciate any help!

Copy link

MdAbuNafeeIbnaZahid commented Aug 27, 2020

hi @russau,
I have been facing the same issue on macOS High Sierra. Stuck here also.

Could you solve the issue?

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.

    from M2Crypto import SMIME, X509, BIO
except ImportError:

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

Copy link

mehdiAberkane commented May 31, 2021

Nice is work, thanks

Copy link

xiazhibin commented Jun 4, 2021


Copy link

bingwork commented Jun 9, 2021

it works for me, thanks.

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

Copy link

laggardkernel commented Mar 10, 2022

 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.

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