源码下载
下载Python源码
wget https://www.python.org/ftp/python/3.11.6/Python-3.11.6.tgz
下载openssl源码
wget https://www.openssl.org/source/old/1.1.1/openssl-1.1.1v.tar.gz
源码编译
openssl编译
tar -zxvf openssl-1.1.1v.tar.z cd openssl-1.1.1v ./config --prefix=/usr/local/openssl make make install
python编译
编译python源码前须要执行
cd /usr/local/openssl ln -s lib64 lib
因为configure会有一段代码对openssl进行编译和链接,会查找头文件和库文件,其中头文件为$ssldir/include/,库文件路径为$ssldir/lib,其中ssldir即为–with-openssl指定的路径,但是/usr/local/openssl路径下只有lib64没有lib,所以创建一个软链接解决,否则找不到ssl模块。
checking for stdlib extension module _lzma... yes checking for stdlib extension module _ssl... no checking for stdlib extension module _hashlib... no checking for stdlib extension module _testcapi... yes
开始安装
CCFLAGS="-I/usr/local/openssl" LDFLAGS="-L/usr/local/openssl/lib" tar -zxvf Python-3.11.6.tgz cd /Python-3.11.6 ./configure --prefix=/usr/local/python3 --with-openssl=/usr/local/openssl --enable-shared make make install
创建软链接
ln -s /usr/local/python3/bin/python3 /usr/bin/python3 ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3