Trouble installing m2crypto with pip on OS X / macOS
Asked Answered
M

7

51
pip install m2crypto

Generates the following output:

building 'M2Crypto.__m2crypto' extension
swigging SWIG/_m2crypto.i to SWIG/_m2crypto_wrap.c
swig -python -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -I/usr/include -I/usr/include/openssl -includeall -modern -o SWIG/_m2crypto_wrap.c SWIG/_m2crypto.i
SWIG/_m2crypto.i:30: Error: Unable to find 'openssl/opensslv.h'
SWIG/_m2crypto.i:33: Error: Unable to find 'openssl/safestack.h'
SWIG/_evp.i:12: Error: Unable to find 'openssl/opensslconf.h'
SWIG/_ec.i:7: Error: Unable to find 'openssl/opensslconf.h'
error: command 'swig' failed with exit status 1

I've run:

brew install swig
Misprint answered 8/10, 2015 at 1:58 Comment(0)
I
179

I wanted a nicer way without installing manually and using only Homebrew (which also does not link openssl by default). Also using pip was a requirement. This seems to work with newest m2crypto 0.22.5. I also tested it once with m2crypto 0.22.3 and seems also to work. The OpenSSL version here is 1.0.2d:

brew install openssl
brew install swig

Finally install m2crypto on macOS in your Bash. It is a long command but it changes SWIG and clang environment variables only during pip install so that m2crypto will get all OpenSSL requirements:

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

btw. the last command also works if you use e.g. a requirements.txt.

Update:
Additional also the command for fish shell users...

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
Ivied answered 14/10, 2015 at 12:32 Comment(2)
+1 Really like this method, I could use it with a recursive dependency install script, and it worked like a charm.Blowtube
woked like a charm :-)Blastopore
J
11

thanks to therealmarv env flags i was able to get this to work with the macports version of openssl/swig, this is what i did:

sudo port install openssl
sudo port install swig
sudo port install swig-python

then use therealmarv lines but replace "$(brew --prefix openssl)" with the dir from macports which should be "/opt/local"

sudo env LDFLAGS="-L/opt/local/lib" \
CFLAGS="-I/opt/local/include" \
SWIG_FEATURES="-cpperraswarn -includeall -I/opt/local/include" \
pip install M2Crypto
Judoka answered 17/10, 2015 at 7:12 Comment(0)
C
5

I just went through a lot of pain getting this working in El Capitan. Here is what I had to do:

Install OpenSSL (you have to use an older version, m2crypto will not compile otherwise)

curl -O https://www.openssl.org/source/openssl-0.9.8zg.tar.gz
tar -xvzf openssl-0.9.8zg.tar.gz
cd openssl-0.9.8zg
./Configure --prefix=/usr/local darwin64-x86_64-cc
make && make test
sudo make install

Install m2crypto

git clone https://github.com/martinpaljak/M2Crypto.git    
cd M2Crypto
python setup.py build build_ext --openssl=/usr/local
sudo python setup.py install build_ext --openssl=/usr/local

AFAIK it is installed... I still have to do some testing though.

Chadburn answered 11/10, 2015 at 3:51 Comment(3)
Also, this repo seems to be more active: gitlab.com/m2crypto/m2crypto.git I think I'll try installing this version as well.Chadburn
I was able to use hjjiang answer from above with OpenSSL 1.0.2eZeralda
python setup.py build build_ext --openssl=/usr/local/opt/openssl sudo python setup.py install build_ext --openssl=/usr/local/opt/openssl works for meBiggers
S
4

Got exact same issue on Ubuntu 18.04 LTS, while trying to execute

pip install M2Crypto==0.24.0

Did the following to get rid of it:

sudo apt-get install swig
sudo apt-get install libssl1.0-dev
Shutout answered 26/6, 2018 at 11:46 Comment(0)
W
1

This fixed my problem (Python 2.7):

export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages
Whitnell answered 30/5, 2017 at 14:2 Comment(0)
K
0

macos v10.15.6
m2crypto v0.35.6
pip v20

Solution by therealmarv works, If the program does not take effect, you can try to upgrade your brew packages. Before the solution.

brew update              # update homebrew self
brew upgrade             # upgrade all 
Kev answered 21/8, 2020 at 1:53 Comment(0)
I
-11

sudo apt-get install python-m2crypto

Inapposite answered 19/10, 2015 at 3:26 Comment(1)
The question is tagged as osx-elcapitan, where apt-get most likely is not available.Aryl

© 2022 - 2024 — McMap. All rights reserved.