项目上有依赖问题,requirement.txt. 使用 pip -r requirement 的方式去安装。发现其中M2Crypto 一直安装不上。对这种问题我最为头疼。
google 大法好:
直接google
mac m2crypto 安装失败
得到这这一篇
http://www.iops.cc/install-m2crypto-failed-with-mac-os-x/
意思是安装一个swig 组件,然后安装低版本的M2Crypto。
pip uninstall m2crypto
brew uninstall swig --force
# Install swig 3.0.4 and compile m2crypto
brew update
brew search swig
brew install homebrew/versions/swig304
brew link homebrew/versions/swig304
pip install m2crypto
在我本机上执行
brew install homebrew/versions/swig304
brew link homebrew/versions/swig304
是会报错的
于是
brew install swig@3.04
接着跑
vim ~/.bash_profile
export PATH=$PATH:/usr/local/opt/swig@3.04/bin
source ~/.bash_profile
这里需要注意要新开终端来执行。
又出现了
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 -includeall -o SWIG/_m2crypto_wrap.c SWIG/_m2crypto.i
SWIG/_m2crypto.i:31: Error: Unable to find 'openssl/opensslv.h'
SWIG/_m2crypto.i:45: 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
找不到 openssl/opensslv.h
google
https://gist.github.com/charlax/38ecd925a8bcb8cadcf5
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
Solution:
$ brew install openssl
$ pip install --global-option=build_ext --global-option="-I/usr/local/opt/openssl/include" m2crypto
用brew 安装 openssl 指定路径
到此安装成功。