从源码编译 Python 指定版本
尝试通过源码编译安装 python 的指定版本,本次安装的是 python3.8.5 版本
下载
官网的下载地址:https://www.python.org/downloads/release/python-385/
下载:Gzipped source tarball
源码压缩包
1 | wget https://www.python.org/ftp/python/3.8.5/Python-3.8.5.tgz |
配置
解压后添加配置
1 | tar -zxvf Python-3.8.5.tgz && cd Python-3.8.5/ |
修改配置文件,启用 SSL 支持
1 | vim Modules/Setup |
去掉如下几行注释
1 | # Socket module helper for SSL support; you must comment out the other |
提前配置好编需要的工具和依赖
1 | apt update && apt install gcc make zlib1g-dev libssl-dev libsqlite3-dev -y |
指定安装位置,指定安装共享库,启用配置文件引导优化 (PGO) 和链接时间优化 (LTO)
(–enable-optimizations)会影响编译速度
1 | ./configure --prefix=/usr/local/python3.8.5 --enable-shared --enable-optimizations |
编译
-j
当前主机的 cpu 核心数
1 | make -j 4 && make install |
建立软链
1 | ln -s /usr/local/python3.8.5/bin/python3.8 /usr/bin/python3 |
查看效果
1 | root@debian:~# python3 --version |
遇到的问题
1 | root@debian:~# python3 |
python3: error while loading shared libraries: libpython3.8.so.1.0: cannot open shared object file: No such file or directory
解决方法
1 | cp /usr/local/python3.8.5/lib/libpython3.8.so.1.0 /usr/lib |
本文采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 ShiGuang
评论