美文网首页
Centos 6 升级 Python 版本

Centos 6 升级 Python 版本

作者: W_Bousquet | 来源:发表于2017-05-24 16:23 被阅读220次

    Centos 6自带的python版本是 2.6 , 但是很多时候一些开发和使用需要2.7版本。接下来,我们升级Python版本从2.6-2.7或者你可以从2.6-3以上,步骤都是类似的。

    1、更新开发工具集

    yum -y update

    yum groupinstall -y 'development tools'

    yum install -y zlib-devel bzip2-devel openssl-devel xz-libs wget

    2、下载和解压你要更新至Python目的版本号

    wget http://mirrors.sohu.com/python/2.7.13/Python-2.7.13.tar.xz

    xz -d Python-2.7.13.tar.xz

    tar -xvf Python-2.7.13.tar

    此过程,解压的文件非常之多。我更新至2.7.13,你随意。

    3、编译

    cd Python-2.7.13

    ./configure --prefix=/usr/local

    make && make install 

    此过程,你可能会遇到跟我一样的错误,不过我觉得可能性很小。是什么样的呢?请看,不过这个错误很容易解决,关键之处我加粗了。

    checking build system type... x86_64-pc-linux-gnu

    checking host system type... x86_64-pc-linux-gnu

    checking for --enable-universalsdk... no

    checking for --with-universal-archs... 32-bit

    checking MACHDEP... linux2

    checking EXTRAPLATDIR...

    checking for --without-gcc... no

    checking for --with-icc... no

    checking for gcc... /home/soft/bin/gcc

    checking whether the C compiler works... no

    configure: error: in `/root/Python-2.7.13':

    configure: error: C compiler cannot create executables

    See `config.log' for more details

    gcc已经安装,看一下目录就能知道错误原因和解决方法。

    [root@cdh Python-2.7.13]#which gcc

    /usr/bin/gcc

    我做了软连接ln -s /usr/bin/gcc /home/soft/bin/gcc/home/soft/bin/gcc

    然后进行编译就通过了。

    If you want a release build with all optimizations active (LTO, PGO, etc),

    please run ./configure --enable-optimizations

    4、验证

    python -V

    which python

    Python 2.7.13

    至此,Python主体升级完毕,一些工具包可以意并安装,方便日后使用。

    5、安装 setuptools

    wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-1.4.2.tar.gz

    tar -xvf setuptools-1.4.2.tar.gz

    python2.7 setup.py install

    6、安装 PIP

    这是重要的,Python的一些库都需要使用pip安装,用起来十分方便。

    curl  https://bootstrap.pypa.io/get-pip.py | python2.7 -

    比如安装flask,pymongo,virtualenv等可以通过pip安装。

    pip install Flask

    pip install pymongo

    pip install virtualenv

    完结。

    相关文章

      网友评论

          本文标题:Centos 6 升级 Python 版本

          本文链接:https://www.haomeiwen.com/subject/frroxxtx.html