编译 CPython 心得
什么情况下需要自己编译 CPython 大多数操作系统都提供了编译好的 CPython 版本,一般直接通过包管理器安装就能满足需求,但是某些情况下,就需要自己编译 CPython 来满足特定需求了: 操作系统提供的 Python 版本太低,并且 Python 官网、系统包管理源没有提供预编译的新版本 Python 预编译版本不符合性能、扩展等方面的要求,比如没有开启编译器优化、OpenSSL/SQLite 版本不满足要求等 参与 CPython 开发或者尝鲜,尝试 Alpha/Beta/RC 等版本的 Python 低版本 Linux 发行版上编译 CPython 时的注意事项 OpenSSL 因为 CentOS 6 官方源中的 OpenSSL 版本过低,不满足 Python 3.7 及之后的要求,所以直接 configure & make 会报错,解决办法: 参考 Python 3.7 on CentOS 6 , 提前编译 OpenSSL, 编译 CPython 时修改 Modules/Setup 文件,并且指定环境变量 LDFLAGS="-Wl,-rpath=/usr/local/openssl11/lib" , 指定参数 -with-openssl=/usr/local/openssl11 。 SQLite Jupyter 等软件依赖 SQLite, 所以编译 CPython 时不仅要注意 SQLite 版本,也要开启 --enable-loadable-sqlite-extensions , 参考:How to use enable_load_extension from sqlite3? ...