Trouble installing m2crypto with pip on OS X / macOS

给你一囗甜甜゛ 提交于 2019-11-29 18:57:07

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

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

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.

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

This fixed my problem (Python 2.7):

export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages

sudo apt-get install python-m2crypto

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!