如果是直接使用pip install M2Crypto安装的话就会出现

SWIG/_m2crypto.i:62: Error: Unable to find 'openssl/opensslv.h'
  SWIG/_m2crypto.i:68: Error: Unable to find 'openssl/safestack.h'
  SWIG/_evp.i:12: Error: Unable to find 'openssl/opensslconf.h'
  SWIG/_rc4.i:5: 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
  ----------------------------------------
  ERROR: Failed building wheel for m2crypto

这样的错误(没写完整哈),这是由于M2Crypto有两个依赖,openssl和swig,在Mac上需要首先安装这两个包,才能安装M2Crypto。
我们可以通过brew来安装这两个包,如果你的电脑没有brew的话,你就得先安装brew,小编在

这篇文章中介绍过怎么安装。下面我们来安装openssl和swig。

brew install openssl
brew install swig
# 有时候需要手动链接swig
# brew unlink swig && brew link swig

这时候就可以安装M2Crypto,不过还是有时候会报错,我们需要指定下地址

env LDFLAGS="-L$(brew --prefix openssl)/lib" CFLAGS="-I$(brew --prefix openssl)/include" SWIG_FEATURES="-cpperraswarn -includeall -I$(brew --prefix openssl)/include"

然后我们就可以安装了M2Crypto

pip install M2Crypto
Last modification:February 24th, 2021 at 11:27 am
If you think my article is useful to you, please feel free to appreciate