美文网首页程序员
linux编译安装Python-3.6.7

linux编译安装Python-3.6.7

作者: hsyman | 来源:发表于2018-12-24 11:26 被阅读3次
    linux版本:centos7
    python版本:3.6.7

    安装开发工具

    [root@localhost ~]# yum -y install  zlib-devel bzip2-devel openssl-devel  sqlite-devel readline-devel gcc make pcre pcre-devel
    
    如果在没有安装开发工具包,在编译的时候就会报一些错。
    看见过很多小伙伴在编译的时候报错了,然后上网各种搜,其实就是开发工具没有安装,在这安装了之后编译的时候就不会报错了,当然也可以安装报错的时候再安装也行!

    下载源码包

    [root@localhost ~] wget https://www.python.org/ftp/python/3.6.7/Python-3.6.7rc2.tgz
    

    编译前的准备

    vi Python-3.6.5/Modules/Setup.dist
    修改

    readline readline.c -lreadline -ltermcap
    
    SSL=/usr/local/ssl
    _ssl _ssl.c \
            -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
            -L$(SSL)/lib -lssl -lcrypto
    

    编译安装

    [root@localhost Python-3.6.7rc2] ./configure --enable-shared
    
    [root@localhost Python-3.6.7rc2] make && make install
    

    vi /etc/profile.d/python3.6.7lib.sh
    添加这么一行

    #python-3.6.7共享库目录
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
    

    vi /etc/ld.so.conf.d/python3.conf
    添加如下内容

    /usr/local/lib
    

    保存退出
    [root@localhost ~]# ldconfig
    [root@localhost ~]# source /etc/profile
    检查是否安装成功、出现如下内容表示安装成功

    [root@localhost ~]# python3
    Python 3.6.7 (default, Dec 24 2018, 11:03:47) 
    [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 
    

    exit()退出

    [root@localhost ~]# python3
    Python 3.6.7 (default, Dec 24 2018, 11:03:47) 
    [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> exit()
    

    最后附上安装脚本

    #!/bin/bash
    #lyoyo
    #install python3.6.7
    yum -y install  zlib-devel bzip2-devel openssl-devel  sqlite-devel readline-devel gcc make pcre pcre-devel
    wget https://www.python.org/ftp/python/3.6.7/Python-3.6.7rc2.tgz
    tar xf Python-3.6.7rc2.tgz
    sed -i "s/^#readline/readline/g" Python-3.6.7rc2/Modules/Setup.dist
    sed -i "s/^#SSL/SSL/g" Python-3.6.7rc2/Modules/Setup.dist
    sed -i "s/^#_ssl/_ssl/g" Python-3.6.7rc2/Modules/Setup.dist
    sed -i "s/^#[\t]*-DUSE_SSL/-DUSE_SSL/g" Python-3.6.7rc2/Modules/Setup.dist
    sed -i "s/^#[\t]*-L\$(SSL)/-L\$(SSL)/g" Python-3.6.7rc2/Modules/Setup.dist
    cd Python-3.6.7rc2
    ./configure --enable-shared
    make && make install
    echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib" >> /etc/profile.d/python-3.6.7_lib.sh
    echo "/usr/local/lib" >> /etc/ld.so.conf.d/python3.conf
    ldconfig
    source /etc/profile
    
    

    相关文章

      网友评论

        本文标题:linux编译安装Python-3.6.7

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