python编译安装

Ling Yu
import sysconfig
# 获取并打印Python编译参数
config = sysconfig.get_config_vars()
print(config["CONFIG_ARGS"])
print(f"CONFIG_ARGS: {config["CONFIG_ARGS"]}")
for key, value in config.items():
print(f"{key}: {value}")
下载
curl -LsSf https://www.python.org/ftp/python/3.13.2/Python-3.13.2.tgz -o python313.tgz
wget https://www.python.org/ftp/python/3.11.8/Python-3.11.8.tgz
tar -zxvf Python-3.11.8.tgz
cd Python-3.11.8
mkdir build && cd build
依赖下载
The necessary bits to build these optional modules were not found:
_bz2 _ctypes _ctypes_test
_curses _curses_panel _dbm
_gdbm _hashlib _lzma
_ssl _tkinter _uuid
readline zlib
optional
apt install libsqlite3-dev libbz2-dev libffi-dev libncurses5-dev libncursesw5-dev libgdbm-compat-dev libgdbm-dev liblzma-dev libssl-dev tk-dev uuid-dev libreadline-dev zlib1g-dev
编译
../configure --prefix=/usr/local/python3.11.8 --enable-shared --enable-ipv6 --enable-loadable-sqlite-extensions --enable-optimizations --with-lto=full --with-openssl-rpath=auto
../configure --prefix=/usr/local/python313 --enable-shared --enable-ipv6 --enable-loadable-sqlite-extensions --enable-optimizations --with-openssl-rpath=auto --with-pkg-config=yes --disable-gil
../configure --prefix=/usr/local/python313 --enable-shared --enable-ipv6 --enable-loadable-sqlite-extensions --without-ensurepip --enable-optimizations --with-lto --with-openssl-rpath=auto --with-pkg-config=yes
export PYTHON313_HOME=/usr/local/python3.13
export PATH=${PYTHON313_HOME}/bin:${PATH} #使得python pip等可执行命令能被找到
export LD_LIBRARY_PATH=${PYTHON313_HOME}/lib:${LD_LIBRARY_PATH} #使得libPython.so.xx等库能被找到