M2Crypto无法在虚拟环境中安装,或者swig未定义__x86_64__,这会导致编译与OpenSSL的兼容性出现问题。

30

我在x86_64 RHEL 6.1机器上的virtualenv中尝试安装Python M2Crypto包。这个过程会调用swig,但是它失败了并显示以下错误:

$ virtualenv -q --no-site-packages venv
$ pip install -E venv M2Crypto==0.20.2
Downloading/unpacking M2Crypto==0.20.2
  Downloading M2Crypto-0.20.2.tar.gz (412Kb): 412Kb  downloaded
  Running setup.py egg_info for package M2Crypto
Installing collected packages: M2Crypto
  Running setup.py install for M2Crypto
    building 'M2Crypto.__m2crypto' extension
    swigging SWIG/_m2crypto.i to SWIG/_m2crypto_wrap.c
    swig -python -I/usr/include/python2.6 -I/usr/include -includeall -o SWIG/_m2crypto_wrap.c SWIG/_m2crypto.i
    /usr/include/openssl/opensslconf.h:31: Error: CPP #error ""This openssl-devel package does not work your architecture?"". Use the -cpperraswarn option to continue swig processing.
    error: command 'swig' failed with exit status 1
    Complete output from command /home/lorin/venv/bin/python -c "import setuptools;__file__='/home/lorin/venv/build/M2Crypto/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /tmp/pip-BFiNtU-record/install-record.txt --install-headers /home/lorin/venv/include/site/python2.6:

我已经通过RedHat的RPM软件包安装了OpenSSL 1.0.0。

导致错误的/usr/include/openssl/opensslconf.h文件的部分内容如下:

#if defined(__i386__)
#include "opensslconf-i386.h"
#elif defined(__ia64__)
#include "opensslconf-ia64.h"
#elif defined(__powerpc64__)
#include "opensslconf-ppc64.h"
#elif defined(__powerpc__)
#include "opensslconf-ppc.h"
#elif defined(__s390x__)
#include "opensslconf-s390x.h"
#elif defined(__s390__)
#include "opensslconf-s390.h"
#elif defined(__sparc__) && defined(__arch64__)
#include "opensslconf-sparc64.h"
#elif defined(__sparc__)
#include "opensslconf-sparc.h"
#elif defined(__x86_64__)
#include "opensslconf-x86_64.h"
#else
#error "This openssl-devel package does not work your architecture?"
#endif

gcc已经定义了正确的变量:

$ echo | gcc -E -dM - | grep x86_64
#define __x86_64 1
#define __x86_64__ 1

但是显然swig没有成功,因为这一行是失败的:

swig -python -I/usr/include/python2.6 -I/usr/include -includeall -o \
  SWIG/_m2crypto_wrap.c SWIG/_m2crypto.i

有没有一种方式可以通过更改我的系统配置来解决这个问题?M2Crypto作为我无法控制的较大脚本的一部分被安装在虚拟环境中,因此避免对M2Crypto文件进行修改将是一件好事。


有一个 fedora_setup.sh 但它需要修改 M2Crypto 文件。 - jfs
@J.F.Sebastian:不熟悉这个,请您提供更多详细信息作为完整答案吗? - Lorin Hochstein
10个回答

26

M2Crypto提供了一个fedora_setup.sh脚本来处理Fedora/RL/CentOs版本的问题,但是pip当然不知道这些。

在pip安装失败后,它会将下载的内容留在venv/build/M2Crypto目录中。执行以下操作:

cd <path-to-your-venv>/venv/build/M2Crypto
chmod u+x fedora_setup.sh
./fedora_setup.sh build
./fedora_setup.sh install

这在我的安装过程中起作用了


4
截至今天(版本1.5.6),pip已经清理了构建目录,因此不需要在其中进行任何操作。 - Peterino

11

你没有安装 swig

尝试:

sudo yum install swig

然后:

sudo easy_install M2crypto

在 Mac OS X 10.9.4 上,我使用 MacPorts 安装了 swig(sudo port install swig)。我还不得不全局安装 Python 的 markupsafe(sudo pip install markupsafe),因为 swig 依赖于它(.../markupsafe/_speedups.so: Error opening or reading file)。 - Peterino
看起来我们还需要使用MacPorts安装swig-python (sudo port install swig-python). - Peterino
当我在Ubuntu上遇到类似的问题时,这对我很有用(当然要使用apt-get而不是yum)。 - user3614014

9
我做了这个,效果非常好:
env SWIG_FEATURES="-cpperraswarn -includeall -I/usr/include/openssl" pip install M2Crypto

当然,在执行以下命令之前,您需要通过sudo yum install swig安装swigg。


5

5

如果你使用的是Ubuntu,建议使用apt-get而不是pip来避免此问题。
apt-get install python-m2crypto


4

1
在我的Ubuntu 10.04系统上,"pip install git+github.com/martinpaljak/M2Crypto.git" 失败并显示 "ValueError: ('Expected version spec in', 'git+github.com/martinpaljak/M2Crypto.git', 'at', '+github.com/martinpaljak/M2Crypto.git')"。 - Paul Whipp
格式化。请在github.com前面添加https、冒号和斜杠。 - Martin Paljak
谢谢您,这对我们保持构建过程的稳定非常有帮助。 - Andrew Roberts
哪个Ubuntu?我马上试一下。 - Martin Paljak
现在试试吧。https://github.com/martinpaljak/M2Crypto/commit/134e1d9e7dde2e63064afa2f7ef82df8107889ea 可能会解决这个问题。 - Martin Paljak
显示剩余2条评论

3
sudo yum install m2crypto

这对我解决了这个问题。


2

我在CentOS 5.8中找到了解决这个问题的新方法,请尝试。

vim setup.py

def finalize_options(self):
  ...
  self.swig_opts.append('-includeall') # after this line
  self.swig_opts.append('-I/usr/include/openssl') # add here

然后执行 python setup.py install 即可。

0
在FreeBSD上,我不仅需要安装Swig(显而易见的部分)(通过sudo pkg install swig),还需要将Swig 2.0可执行文件命名为swig2.0,并且使用swig命令会导致command not found。解决方案:将Swig 2.0建立符号链接以处理swig命令:
ln -s /usr/local/bin/swig2.0 /usr/local/bin/swig

0

看起来问题在于没有安装swig,正如@LeoC所说。

对于那些使用MacOS的人,我建议通过像homebrew这样的软件包管理器下载swig,因为它更干净。

即,您可以运行以下命令:

brew install swig


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接