cygwin下python环境一些包的踩坑记录

坚持使用cygwin下的python,只有一个原因,要使用cygwin环境下unix/gnu-linux工具;但,毕竟cygwin不是真正的unix/linux,有一些问题貌似无法解决的,钻牛角尖折腾半天,结果还是失败,所以有必要做个踩坑记录,或者也可以说是踩雷记录。

貌似无解的一些包

psutil

[psutil (process and system utilities) is a cross-platform library for retrieving information on running processes and system utilization (CPU, memory, ...] 不支持信息参看,其github上的讨论贴 https://github.com/giampaolo/psutil/issues/82

依赖它的一些包,就不要指望安装了,即使装上运行,结果也有可能异常,如 scipy, matplotlib, scipy, scikit-learn,

不过,因为cygwin本身包含了matplotlib 包,可以使用它安装,如果是venv环境,把安装后的文件从 site-packages 里拷到venv下使用,经验上应该没有什么问题。如果运行中提示缺少依赖包(至少包括 mpl_toolkits)也要同步拷过来 。

 

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没有任何影响。