Python 3.7 及以上版本源码安装

Python 3.7+ 源码安装

安装 Python

  • 通过 python 官网下载源码包
  • 通过 yum 安装依赖包
  • 解压编译并安装
#安装依赖包
yum -y install bzip* ncurses*  gdbm*  libpcap* xz*  libffi*  sqlite*  tk* libuuid* readline*  zlib*

#解包源码包
tar -xf Python-3.8.0.tgz

mkdir /opt/sdks/versions/python3.8.0

#编译并安装
./configure -prefix=/opt/sdks/versions/python3.8.0
make & make install

常见错误

OpenSSL依赖问题

因openssl 1.0.1存在安全问题,python3自3.7版本后要求依赖openssl 1.0.2以上或libressl;错误提示如下:

Python requires an OpenSSL 1.0.2 or 1.1 compatible libssl with X509_VERIFY_P
  • 安装libressl
    python3.7以上建议使用libressl代替openssl,故需通过源码编译安装libressl

    # 下载源码包
    wget https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-3.0.2.tar.gz 
    
    # 解压
    tar -zxvf libressl-3.0.2.tar.gz
    # 配置安装路径
    mkdir /usr/local/libressl
    cd libressl-3.0.2
    ./configure --prefix=/usr/local/libressl
    
    # 安装
    make & make install
    
    # 创建软连接代替openssl
    mv /usr/bin/openssl /usr/bin/openssl.bak
    mv /usr/include/openssl /usr/include/openssl.bak 
    ln -s /usr/local/libressl/bin/openssl /usr/bin/openssl 
    ln -s /usr/local/libressl/include/openssl /usr/include/openssl
    echo /usr/local/libressl/lib >> /etc/ld.so.conf.d/libressl-3.0.2.conf
    ldconfig -v
    
    
    export LDFLAGS="-L/usr/local/libressl/lib"
    export CPPFLAGS="-I/usr/local/libressl/include"
    export PKG_CONFIG_PATH="/usr/local/libressl/lib/pkgconfig"
    
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。