https://www.cnblogs.com/mqxs/p/9103031.html
#!/bin/bash
echo "正在安装相关组件"
yum install -y openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel gcc-c++ gcc openssl-devel
echo "下载安装包"
wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
echo "正在解压安装包"
tar -xf Python-3.6.5.tgz -C /root/ && cd /root/Python-3.6.5/
echo "添加ssl支持"
cat >> /root/Python-3.6.5/Modules/Setup.dist <<"EOF"
_socket socketmodule.c
SSL=/usr/local/ssl
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto
EOF
echo "正在编译安装Python"
./configure --prefix=/usr/local/python && make && make install
cd /root
echo "删除安装包"
rm -rf /root/Python-3.6.5.tgz && rm -rf /root/Python-3.6.5
echo "正在添加环境变量"
echo "export PATH=/usr/local/python/bin:$PATH">> ~/.bash_profile
source ~/.bash_profile
echo "安装完成,请执行python3进行测试"
上述如果解决不了可以用下面方法处理
- 确认OpenSSL版本: 确保你系统上的OpenSSL版本与你所使用的Python 3.6.8版本兼容。可通过以下命令查看OpenSSL版本:
/usr/local/openssl/bin/openssl version
- 重新配置并编译Python: 如果确认OpenSSL版本无误,则需要重新编译Python,并确保在编译时链接到正确的OpenSSL库。具体操作请参照之前的回答,注意要清除旧的编译产物并重新运行configure脚本。
如果之前未指定OpenSSL路径,请尝试显式指明OpenSSL头文件和库的位置:
./configure --prefix=/usr/local/python368/ --with-openssl=/usr/local/openssl CPPFLAGS="-I/usr/local/openssl/include" LDFLAGS="-L/usr/local/openssl/lib"
make clean
make -j$(nproc)
sudo make altinstall
- 检查动态链接库依赖: 使用ldd命令检查新编译的Python解释器对OpenSSL库的链接情况,例如(替换为实际路径):
ldd /usr/local/python368/bin/python3.6 | grep ssl
标签:3.6,Python,local,openssl,OpenSSL,python3.6,ssl,devel,安装
From: https://www.cnblogs.com/sjip008/p/18052100