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

我试图将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: 

我已经通过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定义了正确的variables:

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

但是,显然,sw does不会,因为这是失败的路线:

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

有没有办法通过改变我的系统configuration中的东西来解决这个问题? M2Crypto被安装在virtualenv中,作为我无法控制的更大的脚本的一部分,所以避免使用M2Crypto文件是件好事。

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 

这已经在我的安装过程中工作

我这样做,它工作得很好:

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

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

你只是没有安装swig

尝试:

 sudo yum install swig 

接着:

 sudo easy_install M2crypto 

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

我有一个类似的问题,其中/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 

有一个“PIP安装”工作的存储库:

https://github.com/martinpaljak/M2Crypto

 sudo yum install m2crypto 

为我解决这个问题。

我发现了一个新的方法来解决在centos5.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将工作。

在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