Debian 9 编译Python
参考网址:
- https://solarianprogrammer.com/2017/06/30/building-python-ubuntu-wsl-debian/
- https://www.cnblogs.com/freeweb/p/5181764.html
- https://docs.python.org/3/using/unix.html#on-linux
准备工作
-
配置编译环境
- 安装gcc, make, g++
- 安装GCC toolchain
apt-get install build-essential
- 安装编译库
libssl-dev zlib1g-dev libncurses5-dev libncursesw5-dev libreadline-dev libsqlite3-dev libgdbm-dev libdb5.3-dev libbz2-dev libexpat1-dev liblzma-dev tk-dev libffi-dev
-
编译参数
- 设置编译后文件安装位置,默认
/usr/
prefix --- Python模块位置,
${prefix}/lib/pythonversion
exec_prefix --- Python执行位置,${exec_prefix}/bin/python3
默认prefix与exec_prefix相同- 使用优化的设置进行编译
configure --enable-optimizations
- 启用
Link Time Optimization
--with-lto
, LTO当构建最终的可执行文件或共享库以获得额外的性能收益时,LTO利用最近编译器工具链的优势,跨越任意的.o文件边界进行优化。 - 设置编译后文件安装位置,默认
-
编译安装
- 并存安装
If you intend to install multiple versions using the same prefix you must decide which version (if any) is your "primary" version. Install that version using
make install
. Install all other versions usingmake altinstall
.- 安装
make -j n
n为指定的编译线程数
make install