CentOS6.x升级安装python2

2023-01-31 04:01:19 centos6 安装 升级

一、背景说明:

    Centos6.x系统默认自带python 2.6.x,但现在很多自动化运维工具使用最新的2.7.x版本,故要进行兼容性升级

二、安装

采用编译安装,保留原2.6版本

1、升级依赖:

    #yum install GCc gcc-c++ readline-devel zlib-devel openssl-devel sqlite-devel -y

2、×××与安装:

    #wget https://www.Python.org/ftp/python/2.7.12/Python-2.7.12.tgz

    tar xvf Python-2.7.12.tgz

    cd Python-2.7.12

    #./configure --prefix=/usr/local/python27

    #make

    #make install

    #cd /usr/bin

    #mv python python26

    #ln -sf /usr/local/python27/bin/python /usr/bin/python

三、解决yum兼容问题

    #vim /usr/bin/yum   修改第一行

    #!/usr/bin/python  ---> #!/usr/bin/python2.6


四、安装pip   easy_install

    #wget Https://bootstrap.pypa.io/get-pip.py

    #python get-pip.py

    #ln -sf /usr/local/python27/bin/pip /usr/bin/pip

    #ln -sf /usr/local/python27/bin/easy_install /usr/bin/easy_install

五、安装ipython,Mysqldb模块

    #pip install ipython

    #ln -sf /usr/local/python27/bin/ipython   /usr/bin/ipython

    安装mysqldb模块

    #pip install MySQL-python


补充:

导出已经安装的pip模块到文件:

$ pip freeze > mod_install.txt

通过文件安装 python模块:

$ pip install -r mod_install.txt


至此长级python 2.6.6 到2.7.10完成


相关文章