CentOS6.x升级安装python2

发布时间:2019-09-03 09:13:50编辑:auto阅读(1531)

    一、背景说明:

        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完成


关键字