下载源码
下载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
cd /Python-3.11.6
./configure --with-openssl=/usr/local/openssl/
make
make install
运行
运行python3 --version可以正常显示
但使用pip3安装插件时会报如下错误:
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available
猜测是Python编译时没有将ssl模块编译进去;所以回到Python编译步骤;检查tls/ssl模块的加载情况;
再编译
回到Python3的编译过程,发现在./configure --with-openssl=/usr/loca/openssl
查看输出发现ssl模块是missing的
checking for stdlib extension module zlib... yes
checking for stdlib extension module _bz2... yes
... ...
checking for stdlib extension module _ssl... missing
... ...
checking for stdlib extension module _testcapi... yes
checking for stdlib extension module _testclinic... yes
openssl已经安装过,但是这里确显示missing;感觉肯定是openssl查找出现了问题;打开configure文件,发现对ssl进行检测时,configure会有一段代码对openssl进行编译和链接;会查找头文件和库文件;其中头文件为$ssldir/include/,库文件路径为$ssldir/lib,其中ssldir即为--with-openssl指定的路径;打开/usr/local/openssl路径
发现include目录存在,但是只存在lib64目录不存在lib目录;
看到这,感觉可以将configure中lib的查找增加对lib64的查找应该就可以达成目的;但是秉着源码能不修改就不修改的原则;采取了另一个方法,对/usr/local/openssl/中,增加一个软连接lib指向lib64,这样同样达到效果
cd /usr/local/openssl
ln -s lib64 lib
而后,对Pyton进行重新编译
./configure --with-openssl=/usr/loca/openssl
再查看ssl模块的加载情况,发现ssl已经加载成功了
checking for stdlib extension module zlib... yes
checking for stdlib extension module _bz2... yes
checking for stdlib extension module _lzma... missing
checking for stdlib extension module _ssl... yes
checking for stdlib extension module _hashlib... yes
checking for stdlib extension module _testcapi... yes
checking for stdlib extension module _testclinic... yes
checking for stdlib extension module _testinternalcapi... yes
然后再执行make 发现还是出现了一个错误
*** WARNING: renaming "_ssl" since importing it failed: libssl.so.1.1: cannot open shared object file: No such file or directory
*** WARNING: renaming "_hashlib" since importing it failed: libcrypto.so.1.1: cannot open shared object file: No such file or directory
看上去是动态加载libssl及libcrypto.so的时候出了问题;
使用修改LD_LIBRARY_PATH的方式
export LD_LIBRARY_PATH=/usr/local/openssl/lib:$LD_LIBRARY_PATH
ldconfig
而后再进行编译编译可以正常通过
make
make install
验证
pip3 install numpy
可以正常运行