Centos安装Python3.7

作者: 华彩少年 | 来源:发表于2020-01-10 20:07 被阅读0次

    1.准备编译环境

    yum -y groupinstall "Development tools"
    yum -y install gcc zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
    yum install -y libffi-devel zlib1g-dev
    yum install zlib* -y
    

    Centos7 以下系统的要注意openssl 版本,不能低于 1.0.2
    openssl 如何升级版本,请看我上一篇文章

    # openssl version
    OpenSSL 1.0.2o  27 Mar 2018
    

    2.下载Python3.7.2源码包

    (国外源,下载比较慢)

    wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tar.xz
    

    3.解压

    tar -xvf  Python-3.7.2.tar.xz
    

    4.创建编译安装目录并安装

    需要openssl 版本在 1.0.2 及以上,否则无法导入ssl模块,pip install 也会报错

    cd Python-3.7.2/
    ./configure --prefix=/usr/local/python3 --with-openssl=/usr/local/ssl --enable-optimizations(加快代码运行速度)
    make && make install
    ln -s /usr/local/python3/bin/python3 /usr/local/bin/
    ln -s /usr/local/python3/bin/pip3 /usr/local/bin/
    

    --enable-optimizations 加快代码运行效率,会导致编译时间过长,可忽略.centos6系统不要加这个,编译会卡着不动
    --with-openssl=/usr/local/ssl 指定openssl安装位置 ,通过yum 安装openssl >=1.0.2版本的不需要该选项,

    5.测试

    #python3
    Python 3.7.2 (default, Jan 10 2020, 18:08:10)
    [GCC 4.8.2 20131212 (Red Hat 4.8.2-8)] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import ssl
    >>>
    

    更换pip为国内源

    #mkdir ~/.pip/
    #vim ~/.pip/pip.conf
    [global]
    index-url = https://mirrors.aliyun.com/pypi/simple
    

    相关文章

      网友评论

        本文标题:Centos安装Python3.7

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