• Python3.7源码编译


    1.下载Python3.7.0源码

    git clone https://github.com/python/cpython.git
    git checkout v3.7.0
    
    wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz
    

    源码目录结构如下所示:
    (1)Include目录:包含Python提供的所有头文件,如果用户需要自己用C或C++来编写自定义模块扩展Python,那么就需要用到这里提供的头文件。
    (2)Lib目录:包含了Python自带的所有标准库,且都是用Python语言编写的。
    (3)Modules目录:包含了所有用C语言编写的模块,比如math、hashlib等。它们都是那些对速度要求非常严格的模块。而相比而言,Lib目录下则是存放一些对速度没有太严格要求的模块,比如os。
    (4)Parser目录:包含了Python解释器中的Scanner和Parser部分,即对Python源代码进行词法分析和语法分析的部分。除此以外,此目录还包含了一些有用的工具,这些工具能够根据Python语言的语法自动生成Python语言的词法和语法分析器,与YACC(Yet Another Compiler Compiler)非常类似。
    (5)Objects目录:包含了所有Python的内建对象,包括整数、list、dict等。同时,该目录还包括了Python在运行时需要的所有的内部使用对象的实现。
    (6)Python目录:包含了Python解释器中的Compiler和执行引擎部分,是Python运行的核心所在。
    (7)PCbuild目录:包含了Visual Studio 2003的工程文件,研究Python源代码就从这里开始。
    (8)Programs目录:包含了Python二进制可执行文件的源码。

    2.编译和安装Python3.7.0源码
    libffi是Python中用来支持C扩展的库:

    sudo apt install -y zlib1g zlib1g-dev libffi-dev openssl libssl-dev
    
    ./configure --prefix=/home/rasa/Downloads/PythonSorceCode/Python3.7_compile
    make
    make install
    

    make命令后报错如下所示: 因为openssl 1.0.1存在安全问题,所以Python3.7以上建议使用libressl代替openssl,故需通过源码编译安装libressl,如下所示:

    # 下载和编译libressl
    wget https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-3.0.2.tar.gz
    tar -zxvf libressl-3.0.2.tar.gz
    sudo mkdir /usr/local/libressl
    cd libressl-3.0.2
    ./configure --prefix=/usr/local/libressl && make && sudo make 
    # 创建软连接代替openssl
    sudo mv /usr/bin/openssl /usr/bin/openssl.bak
    sudo mv /usr/include/openssl /usr/include/openssl.bak
    sudo ln -s /usr/local/libressl/bin/openssl /usr/bin/openssl
    sudo 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
    sudo ldconfig -v
    # 验证是否安装完成
    openssl version
    
    export LDFLAGS="-L/usr/local/libressl/lib"
    export CPPFLAGS="-I/usr/local/libressl/include"
    export PKG_CONFIG_PATH="/usr/local/libressl/lib/pkgconfig"
    

    再次执行命令编译Python3.7.0源码:

    ./configure --prefix=/home/rasa/Downloads/PythonSorceCode/Python3.7_compile
    make
    sudo make install
    

    参考文献:
    [1]Python源代码的组织:https://flaggo.github.io/python3-source-code-analysis/preface/code-organization/
    [2]Python requires an OpenSSL 1.0.2 or 1.1 compatible libssl with X509_VERIFY_P:https://www.cnblogs.com/apexchu/p/16294733.html

  • 相关阅读:
    并发编程(三)原子性(2)
    Java内存区域介绍以及JDK1.8内存变化
    树的入门与习题
    otn 709帧结构
    浙大陈越何钦铭数据结构06-图1 列出连通集
    定时器 | Spring Task 定时器
    ARM32开发-fat_fs文件系统
    redis中使用lua脚本
    java基础巩固6
    详解IP安全:IPSec协议簇 | AH协议 | ESP协议 | IKE协议
  • 原文地址:https://www.cnblogs.com/shengshengwang/p/17510011.html