惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

美团技术团队
阮一峰的网络日志
阮一峰的网络日志
T
The Blog of Author Tim Ferriss
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
宝玉的分享
宝玉的分享
L
LangChain Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Last Week in AI
Last Week in AI
博客园 - 司徒正美
M
MIT News - Artificial intelligence
人人都是产品经理
人人都是产品经理
WordPress大学
WordPress大学
B
Blog RSS Feed
H
Hackread – Cybersecurity News, Data Breaches, AI and More
博客园 - Franky
B
Blog
V
V2EX
J
Java Code Geeks
D
Docker
博客园 - 叶小钗
The Cloudflare Blog
量子位
博客园_首页
MongoDB | Blog
MongoDB | Blog

秋水逸冰

丽萨主机:双ISP家宽住宅IP VPS/CN2 GIA精品网/G口大带宽 | 秋水逸冰 Linux Kernel 6.18.x 编译版 | 秋水逸冰 思考未来人与 AI 的关系 | 秋水逸冰 3X-UI 面板安装和使用教程 | 秋水逸冰 Xray-UI 面板安装和使用教程 | 秋水逸冰 WCMP (Windows + Caddy + MariaDB + PHP) Nginx for Windows | 秋水逸冰 Aria2 for Windows | 秋水逸冰 Curl for Windows | 秋水逸冰 Wget for Windows | 秋水逸冰 Windows 11 Enterprise LTSC DD 镜像 Windows Server 2025 Datacenter DD 镜像 重新编译 curl 以支持 HTTP3 | 秋水逸冰 tiny10 和 tiny11 23H2 的 Windows DD 镜像 从 Apache httpd 切换到 Caddy2 LCMP (Linux + Caddy + MariaDB + PHP) Windows 11 Pro for Workstations 22H2 DD 镜像 Shadowsocks 编译版 by Teddysun | 秋水逸冰 适用于 UEFI 启动的多个 Windows 系统 DD 镜像 Linux Kernel 5.15.x 编译版 | 秋水逸冰 制作适用于 WSL 的任意 Linux 镜像 Windows 11 Pro for Workstations 21H2 DD 镜像 Windows 10 Enterprise LTSC DD 镜像 Linux Kernel 5.14.x 编译版 | 秋水逸冰 Linux Kernel 5.13.x 编译版 | 秋水逸冰 Windows Server 2022 Datacenter DD 镜像 在 Windows 10 上安装 Rocky Linux 系统 Linux Kernel 5.12.x 编译版 | 秋水逸冰 Linux Kernel 5.11.x 编译版 | 秋水逸冰 在 Windows 10 上安装 CentOS 系统
解决pip安装M2Crypto失败的问题 | 秋水逸冰
秋水逸冰 · 2015-11-30 · via 秋水逸冰

技术 秋水逸冰 39661浏览 6评论

Linux

M2Crypto 是最完整的为 Python 包装 OpenSSL 的 RSA,DSA,DH,EC,HMACs,消息摘要,对称密码算法(包括AES)的一个库工具。
而自从 M2Crypto 升级到版本 0.22.5 后,用 pip install M2Crypto 命令来安装 M2Crypto 时总是会失败。
在没有升级到此版本之前,使用 pip 安装则是没有问题的。下面来找找原因。
系统环境:CentOS 6.7 x86
失败关键字:swig

失败现象:

swigging SWIG/_m2crypto.i to SWIG/_m2crypto_wrap.c
swig -python -I/usr/include/python2.6 -I/usr/include -includeall -modern -builtin -outdir build/lib.linux-i686-2.6/M2Crypto -D__i386__ -o SWIG/_m2crypto_wrap.c SWIG/_m2crypto.i
swig error : Unrecognized option -builtin
Use 'swig -help' for available options.
error: command 'swig' failed with exit status 1

这里有个最为明显的错误提示:
swig error : Unrecognized option -builtin

这说明,系统里安装的 swig 是没有 -builtin 这个选项的。来看看系统装的 swig 版本。
rpm -qa | grep swig
返回:
swig-1.3.40-6.el6.i686
是不是版本比较旧的缘故导致的呢?再来看看 swig 的帮助。
swig -help
看到其中有:
Note: ‘swig -<lang> -help’ displays options for a specific target language.
因为是涉及到 Python,换个命令来看看。
swig -python -help
返回(节选):
-buildnone      – Use Py_BuildValue() to obtain Py_None (default in Windows)
注意其中的 options,果然是没有 -builtin 这个选项的。

好吧很明显,安装 M2Crypto 所依赖的 swig 版本升级了,而 CentOS 默认的 swig 版本过低了。
下面来升级 swig 版本。官网最新版已经到了 3.0.7 了,就编译安装此版本的。

wget -O swig-3.0.7.tar.gz http://prdownloads.sourceforge.net/swig/swig-3.0.7.tar.gz
tar zxf swig-3.0.7.tar.gz
cd swig-3.0.7
./configure --prefix=/usr
make && make install

安装完成后,再来看一下版本号。
swig -version
返回:
SWIG Version 3.0.7

至此,升级 swig 完成。再来看看新版本的 swig 到底有没有 -builtin 这个选项。
swig -python -help
返回(节选):
-buildnone      – Use Py_BuildValue() to obtain Py_None (default in Windows)
-builtin        – Create new python built-in types, rather than proxy classes, for better performance

果然如此。既然如此,那赶紧继续用 pip 安装 M2Crypto 吧。
pip install M2Crypto

Boom,又出错了。错误信息如下:

swigging SWIG/_m2crypto.i to SWIG/_m2crypto_wrap.c
swig -python -I/usr/include/python2.6 -I/usr/include -includeall -modern -builtin -outdir build/lib.linux-i686-2.6/M2Crypto -D__i386__ -o SWIG/_m2crypto_wrap.c SWIG/_m2crypto.i
/usr/include/openssl/opensslconf.h:13: Error: Unable to find 'opensslconf-i386.h'
error: command 'swig' failed with exit status 1

原因是什么呢?M2Crypto 没找到 openssl 的头文件 opensslconf-i386.h
如果是在 x86_64 下安装的话,会找不到 opensslconf-x86_64.h

怎么办呢?看来是不能通过 pip 来安装了,那我们手动来。

wget --no-check-certificate -O M2Crypto-0.22.5.tar.gz https://pypi.python.org/packages/source/M/M2Crypto/M2Crypto-0.22.5.tar.gz
tar zxf M2Crypto-0.22.5.tar.gz
cd M2Crypto-0.22.5
cp /usr/include/openssl/opensslconf-i386.h ./  #手动把头文件复制过来(适用于x86)
cp /usr/include/openssl/opensslconf-x86_64.h ./  #手动把头文件复制过来(适用于x86_64)
python setup.py install

好了,这下终于安装完成了。看看成果:
pip list | grep M2Crypto
返回:
M2Crypto (0.22.5)

后来我去到 M2Crypto 的官网去看了下,已经有人跟作者反映了这个事情。
https://gitlab.com/m2crypto/m2crypto/issues/69
希望作者能在下个版本改进吧。

转载请注明:秋水逸冰 » 解决pip安装M2Crypto失败的问题