Linux M2Crypto 没有安装在 venv 中,或者 swig 没有定义 __x86_64__ 这会破坏针对 OpenSSL 的编译

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7772965/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 06:42:32  来源:igfitidea点击:

M2Crypto doesn't install in venv, or swig doesn't define __x86_64__ which breaks compiling against OpenSSL

pythonlinuxopensslswigvirtualenv

提问by Lorin Hochstein

I'm trying to install the Python M2Crypto package into a virtualenv on an x86_64 RHEL 6.1 machine. This process invokes swig, which fails with the following error:

我正在尝试将 Python M2Crypto 包安装到 x86_64 RHEL 6.1 机器上的 virtualenv 中。此过程调用 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:

I've got OpenSSL 1.0.0 installed via RPM packages from RedHat.

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

The part of /usr/include/openssl/opensslconf.h that causes the error looks like this:

导致错误的 /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 has the right variable defined:

gcc 定义了正确的变量:

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

But apparenty swig doesn't, since this is the line that's failing:

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

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

Is there a way to fix this by changing something in my system configuration? M2Crypto gets installed in a virtualenv as part of a larger script I don't control, so avoiding mucking around with the M2Crypto files would be a good thing.

有没有办法通过更改系统配置中的某些内容来解决此问题?M2Crypto 作为我无法控制的更大脚本的一部分安装在 virtualenv 中,因此避免与 M2Crypto 文件混在一起是一件好事。

采纳答案by Pamela McA'Nulty

M2Crypto supplies a fedora_setup.sh script to handle the problems with Fedora/RL/CentOs releases, but pip, of course, doesn't know anything about it.

M2Crypto 提供了一个 fedora_setup.sh 脚本来处理 Fedora/RL/CentOs 版本的问题,但是 pip 当然对此一无所知。

After the pip install fails, it leaves the downloaded stuff in the venv/build/M2Crypto directory. do this:

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

This has worked in my install process

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

回答by nknj

If you are seeing this and are on Ubuntu, use apt-get instead of pip to avoid this issue.
apt-get install python-m2crypto

如果你看到这个并且在 Ubuntu 上,使用 apt-get 而不是 pip 来避免这个问题。
apt-get install python-m2crypto

回答by Matt

sudo yum install m2crypto

worked for me to get around this problem.

为我解决了这个问题。

回答by Martin Paljak

There's a repository where "pip install" works:

有一个“pip install”可以工作的存储库:

https://github.com/martinpaljak/M2Crypto

https://github.com/martinpaljak/M2Crypto

回答by LeoC

You just don't have swiginstalled.

你只是没有swig安装。

Try:

尝试:

sudo yum install swig

And then:

进而:

sudo easy_install M2crypto

回答by hahakubile

I found a new way to fix this problem in centos5.8, try it.

我在centos5.8中找到了解决这个问题的新方法,试试吧。

vim setup.py

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

then python setup.py installwill work.

然后python setup.py install会工作。

回答by evendiagram

I had a similar issue where /usr/include/opensslwas missing opensslconf.h(source https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=733644#10)

我有一个类似的问题/usr/include/openssl丢失opensslconf.h(来源https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=733644#10

sudo ln -s /usr/include/x86_64-linux-gnu/openssl/opensslconf.h /usr/include/openssl

回答by chocobn69

I did this and it works very well :

我这样做了,效果很好:

env SWIG_FEATURES="-cpperraswarn -includeall -I/usr/include/openssl" pip install M2Crypto

Of course you have to install swigg with sudo yum install swigbefore

当然,你必须安装swigg与sudo yum install swig

回答by wanaryytel

On FreeBSD I had to install Swig (the obvious part) as well (by sudo pkg install swig), but Swig 2.0 executable was named swig2.0and handle swigresulted in command not found. Solution: symlink Swig 2.0 to handle swig:

在FreeBSD我必须安装痛饮(明显的部分),以及(通过sudo pkg install swig),但痛饮2.0可执行文件被命名为swig2.0和手柄swig导致command not found。解决方案:符号链接 Swig 2.0 来处理swig

ln -s /usr/local/bin/swig2.0 /usr/local/bin/swig