首页 > 代码库 > linux升级python2.7,安装pip,setuptools,zlib

linux升级python2.7,安装pip,setuptools,zlib

1,在192.168.0.65装python2.7和PIP
    #ssh 192.168.0.65
        升级到python2.7
    #cd /usr/local
    #wget https://www.python.org/ftp/python/2.7.10/Python-2.7.10.tgz    
    # tar zxvf Python-2.7.10.tgz
    # cd Python-2.7.10
    # mkdir /usr/local/Python2.7
    # ./configure --prefix=/usr/local/Python2.7
    #make && make install
    #which python   
    # mv /usr/bin/python /usr/bin/python_old   
    # ln -s /usr/local/Python2.7/bin/python2.7 /usr/bin/python 
    参考文档http://www.cnblogs.com/lanxuezaipiao/archive/2012/10/21/2732864.html
     安装pip之前需要先安装zlib,setuptools
    安装zlib
    #yum -y install zlib报错了,如下:
       No module named yum
     
    这个错误的原因是我升级了python,导致yum无法使用。
    参考文档 :http://blog.csdn.net/ei__nino/article/details/8495295
    解决办法:
    # vi /usr/bin/yum
       #!/usr/bin/python_old
       //文件第一行内容改为 #!/usr/bin/python_old,因为我把旧的python重命名为python_old了。而yum匹配的是旧的python。
    # /sbin/service yum-updatesd restart
    # yum -y install zlib zlib-devel  
      //安装成功!但是安装setuptools依旧报错。需要重新编译python。
    参考文档 http://www.idjango.com/content/0/
    下面重新编译python
    # cd /usr/local/Python-2.7.10
    # ./configure --prefix=/usr/local/Python2.7
    #make && make install
    安装setuptools
    # cd /usr/local
    # curl -O https://pypi.python.org/packages/source/s/setuptools/setuptools-2.0.tar.gz
    # tar zxvf setuptools-2.0.tar.gz
    # cd setuptools-2.0
   #python setup.py build
   #python setup.py install//成功
    安装PIP
     PIP官网    https://pypi.python.org/pypi/pip
    #cd /usr/local
    # curl -O https://pypi.python.org/packages/source/p/pip/pip-7.1.2.tar.gz#md5=3823d2343d9f3aaab21cf9c917
    # curl -O https://pypi.python.org/packages/source/p/pip/pip-7.1.2.tar.gz
    用wget下载时会报错,这里改用curl -O即可,这2个命令下载的包都是对的
    # tar zxvf pip-7.1.2.tar.gz     
    # cd pip-7.1.2    
    # python setup.py install
    # ln -s /usr/local/Python2.7/bin/pip /usr/bin/pip
    //pip默认安装到了/usr/local/Python2.7/bin/下面  
    #pip  //测试pip
    报错啦:ImportError: cannot import name HTTPSHandler
    原因在于openssl,openssl-devel两个文件包未正确安装
    解决办法:
    #yum install openssl openssl-devel -y
   继续报错,然后我重新编译了python和pip。OK不再报错了。

备注:升级安装之前先用yum安装zlib、zlib-devel、openssl、openssl-devel。

然后在

进入python安装包,找到Setup文件,用 vi 打开

  1. cd Python-2.7.11/Modules

  1. vi Setup.dist

找到

  1. # Socket module helper for SSL support; you must comment out the other

  1. # socket line above, and possibly edit the SSL variable:

  1. #SSL=/usr/local/ssl#_ssl _ssl.c \

  1. #       -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \

  1. #       -L$(SSL)/lib -lssl -lcrypto

把前面的 # 号去掉,修改为

  1. # Socket module helper for SSL support; you must comment out the other

  1. # socket line above, and possibly edit the SSL variable:

  1. SSL=/usr/local/ssl

  1. _ssl _ssl.c \

  1.        -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \       -L$(SSL)/lib -lssl -lcrypto

保存退出,

去掉ssl、zlib相关注释,使模块生效。

本文出自 “梦想照进现实” 博客,请务必保留此出处http://lookingdream.blog.51cto.com/5177800/1900626

linux升级python2.7,安装pip,setuptools,zlib