Trouble installing m2crypto with pip on OS X / mac

2019-01-29 23:43发布

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

6条回答
Animai°情兽
2楼-- · 2019-01-29 23:46

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
查看更多
ら.Afraid
3楼-- · 2019-01-30 00:00

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.

查看更多
The star\"
4楼-- · 2019-01-30 00:04

This fixed my problem (Python 2.7):

export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages
查看更多
家丑人穷心不美
5楼-- · 2019-01-30 00:05

sudo apt-get install python-m2crypto

查看更多
叼着烟拽天下
6楼-- · 2019-01-30 00:07

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
查看更多
对你真心纯属浪费
7楼-- · 2019-01-30 00:08

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
查看更多
登录 后发表回答