pip install m2crypto安装报错:opensslconf.h Error: CPP #error This openssl-devel package does not work your architecture

centos 7下,安装shadowsocks,提示需要m2crypto依赖包,M2Crypto is required to use aes-256-cfb, please run `apt-get install python-m2crypto`

通过pip安装之,但提示错误消息如下

[root@fsc tmp]# pip install m2crypto
Downloading/unpacking m2crypto
  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.7 -I/usr/include -I/usr/include/openssl -includeall -modern -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 /usr/bin/python -c "import setuptools;__file__='/tmp/pip-build-feng/m2crypto/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-vpkm7l-record/install-record.txt --single-version-externally-managed:
    running install

running build

running build_py

running build_ext

building 'M2Crypto.__m2crypto' extension

swigging SWIG/_m2crypto.i to SWIG/_m2crypto_wrap.c

swig -python -I/usr/include/python2.7 -I/usr/include -I/usr/include/openssl -includeall -modern -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

----------------------------------------
Command /usr/bin/python -c "import setuptools;__file__='/tmp/pip-build-feng/m2crypto/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-vpkm7l-record/install-record.txt --single-version-externally-managed failed with error code 1 in /tmp/pip-build-feng/m2crypto
Storing complete log in /root/.pip/pip.log

安装m2crypto后,再pip安装即可。

 

CentOS6.x下安装python2.7

CentOS6.x自带的python是2.6.x版,一直没有更新到2.7,其上游发行版redhat太过保守了。goagent的新版本已经要求python2.7以上版本了,为了升级goagent,决定安装python2.7.

一个原则:不要去改动系统自带的东西,除非你知道所有不得影响。

考虑到默认位置下的python是系统运行所需,覆盖升级有可能影响一些功能;并且yum update时,可能新装的python会被再次覆盖。所以计划将python2.7装到/opt/python2.7目录下。

在普通用户下下载编译python2.7,个人习惯,软件包都在 ~/optdata/software/build下编译,原源tar包放在 ~/optdata/software/source/下

cd ~/optdata/software/build/
wget http://www.python.org/ftp/python/2.7.5/Python-2.7.5.tar.bz2  #下载python2.7源码
tar xvf Python-2.7.5.tar.bz2         #解压
mv Python-2.7.5.tar.bz2 ../source/   #将源码移到~/optdata/software/source/下
mv Python-2.7.5/ python-2.7.5/       #不喜欢文件名里带大写,改首字母为小写
cd python-2.7.5/
./configure --help                   #查看配置参数,其中主要看--prefix参数,即配置安装目标位置
./configure --prefix=/opt/python2.7  #运行配置。如果你的系统缺少部分开发包,可能会报错,按错误提示yum install 相应的包
make

完成后,su切换到root下,make install安装。

现在python2.7即安装好了,如需使用python2.7,就要指定其完整的路径/opt/python2.7./bin/python

但,这个python只是个基本环境,可能要装一些新模块。pip是个很好用的工具,我们先安装它,有了pip,就可以自动安装了,跟yum一样方便的工具。

下载,个人的python包一般是放在~/optdata/software/python/里

cd ~/optdata/software/python/
wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py
/opt/python2.7/bin/python ez_setup.py
wget https://raw.github.com/pypa/pip/master/contrib/get-pip.py
/opt/python2.7/bin/python get-pip.py

查看下pip版本号,安装pyOpenSSL试试,goagent客户端要用这个包的

/opt/python2.7/bin/pip -V
/opt/python2.7/bin/pip install pyOpenSSL

没问题,完成。

这样如果需要使用python2.7就这样指定/opt/下完整路径运行。而对系统自带的python2.7没有任何影响。