在使用Mac安装M2Crypto的时候需要先安装两个依赖
brew install openssl
brew install swig
安装完依赖安装M2Crypto的时候碰到了下面的错误
pip3.6 install M2Crypto
src/SWIG/_m2crypto.i:62: Error: Unable to find 'openssl/opensslv.h'
src/SWIG/_m2crypto.i:68: Error: Unable to find 'openssl/safestack.h'
src/SWIG/_evp.i:12: Error: Unable to find 'openssl/opensslconf.h'
src/SWIG/_rc4.i:5: Error: Unable to find 'openssl/opensslconf.h'
src/SWIG/_ec.i:7: Error: Unable to find 'openssl/opensslconf.h'
error: command 'swig' failed with exit status 1
在网上搜索都是统一的设置三个环境变量,不能解决我的问题
env LDFLAGS="-L$(brew --prefix openssl)/lib"
CFLAGS="-I$(brew --prefix openssl)/include"
SWIG_FEATURES="-cpperraswarn -includeall -I$(brew --prefix openssl)/include"
于是自己从官网上下载了M2Crypto的安装包
https://pypi.org/project/M2Crypto/
解压之后在 M2Crypto-0.38.0 目录下执行
python3.6 setup.py install
然后依次修改对应报错信息的文件代码(设置openssl/opensslv.h的路径):
./src/SWIG/_m2crypto.i:62: Error: Unable to find 'openssl/opensslv.h'
我安装的openssl路径是:/usr/local/opt/openssl@1.1/include/
把对应的地址修改为自己的openssl地址即可
# include <openssl/opensslconf.h> 修改为
# include </usr/local/opt/openssl@1.1/include/openssl/opensslconf.h>
要修改的文件大致如下:
src/SWIG/_m2crypto.i:62: Error: Unable to find 'openssl/opensslv.h'
src/SWIG/_m2crypto.i:68: Error: Unable to find 'openssl/safestack.h'
src/SWIG/_evp.i:12: Error: Unable to find 'openssl/opensslconf.h'
src/SWIG/_rc4.i:5: Error: Unable to find 'openssl/opensslconf.h'
src/SWIG/_ec.i:7: Error: Unable to find 'openssl/opensslconf.h'
src/SWIG/_ssl.i:31: Error: Unable to find 'openssl/safestack.h'
/usr/local/opt/openssl@1.1/include/openssl/safestack.h:13: Error: Unable to find 'openssl/stack.h'
/usr/local/opt/openssl@1.1/include/openssl/safestack.h:14: Error: Unable to find 'openssl/e_os2.h'
/usr/local/opt/openssl@1.1/include/openssl/opensslconf.h:13: Error: Unable to find 'openssl/opensslv.h'
/usr/local/opt/openssl@1.1/include/openssl/e_os2.h:13: Error: Unable to find 'openssl/opensslconf.h'
然后就大功告成啦~开心