centos stream 9 编译 python3.11.5 源代码
参考官方指导 https://devguide.python.org/getting-started/setup-building
wget https://www.python.org/ftp/python/3.11.5/Python-3.11.5.tgz
tar -zxvf Python-3.11.5.tgz
cd Python-3.11.5
执行配置帮助
./configure --help
主要是想设置安装路径
Installation directories:
--prefix=PREFIX install architecture-independent files in PREFIX
[/usr/local]
--exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
[PREFIX]
By default, `make install' will install all the files in
`/usr/local/bin', `/usr/local/lib' etc. You can specify
an installation prefix other than `/usr/local' using `--prefix',
for instance `--prefix=$HOME'.
安装到当前用户的路径下再配置环境变量即可,不脏了系统级/usr
的环境
mkdir -p $HOME/usr/Python-3.11.5
./configure --prefix=/home/kun/usr/Python-3.11.5 --enable-loadable-sqlite-extensions --enable-shared --enable-optimizations
make -j16
执行configure或者make都可能会出现各种依赖缺失的问题,dnf安装或者找到依赖的源代码编译安装即可
我执行make得到的信息如下:
The necessary bits to build these optional modules were not found:
_dbm _gdbm _hashlib
_ssl _tkinter _uuid
nis readline
To find the necessary bits, look in setup.py in detect_modules() for the module's name.
The following modules found by detect_modules() in setup.py have not
been built, they are *disabled* by configure:
_sqlite3
Could not build the ssl module!
Python requires a OpenSSL 1.1.1 or newer
三个问题:
- 一些必要的库没有安装
- sqlite3默认禁用
- openssl库
解决如下:
- 依赖
sudo dnf install libuuid-devel readline-devel tk-devel
wget https://ftp.gnu.org/gnu/gdbm/gdbm-1.23.tar.gz
mkdir -p $HOME/usr/gdbm-1.23
tar -zxvf
./configure --prefix=$HOME/usr/gdbm-1.23 --enable-libgdbm-compat --enable-debug
export PATH=/home/kun/usr/gdbm-1.23/bin:$PATH
export LD_LIBRARY_PATH=$HOME/usr/gdbm-1.23/lib:$LD_LIBRARY_PATH
sudo dnf install sqlite-devel
通过./configure -h
查到添加--enable-loadable-sqlite-extensions
选项即可- 缺少openssl,dnf安装
sudo dnf install openssl openssl-devel
清空刚刚make的缓存,然后重新config
config的时候添加上_sqlite3
的支持,因为上边log中给出_sqlite3
被禁用了
make distclean
./configure --prefix=/home/kun/usr/Python-3.11.5 --enable-loadable-sqlite-extensions
再次make
然后添加$HOME/usr/Python-3.11.5
到PATH
即可
export PATH=/home/kun/usr/Python-3.11.5/bin:$PATH
export LD_LIBRARY_PATH=$HOME/usr/Python-3.11.5/lib:$LD_LIBRARY_PATH
export C_INCLUDE_PATH=$HOME/usr/Python-3.11.5/include:$C_INCLUDE_PATH
export CPLUS_INCLUDE_PATH=$HOME/usr/Python-3.11.5/include:$CPLUS_INCLUDE_PATH