| 
 在centos7系统中,安装原来的办法安装python3.6,在使用request库 时,系统会提示  
报错信息: Can't connect to HTTPS URL because the SSL module is not available  
问题分析:  
查看系统openssl版本:  
  [root@zj ~]# openssl version -a 
  
  OpenSSL 1.0.1e 
  
  百度后发现ssl版本必须要是1.1或者1.0.2之后的版本,或者安装了2.6.4之后的libressl。 
  
  开始探索之路: 
  
  方法一: 
  
 
 
   1、下载openssl-1.0.2h.tar.gz 
   
 
   wget https://www.openssl.org/source/openssl-1.0.2h.tar.gz 
   
 
   2、更新zlib 
   
 
   yum install -y zlib 
   
 
   3、解压安装 
   
 
   tar zxf openssl-1.0.2h.tar.gz 
   
 
   cd openssl-1.0.2h 
   
 
   ./config shared zlib 
   
 
   make && make install 
   
 
     
   
 
   mv /usr/bin/openssl /usr/bin/openssl.bak 
   
 
   mv /usr/include/openssl /usr/include/openssl.bak 
   
 
   ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl 
   
 
   ln -s /usr/local/ssl/include/openssl /usr/include/openssl 
   
 
   echo “/usr/local/ssl/lib” >> /etc/ld.so.conf 
   
 
   ldconfig -v 
   
 
     
   
 
   4、查看是否升级成功 
   
 
   [root@zj ~]# openssl version -a 
   
 
   OpenSSL 1.0.2h 3 May 2016 
   
    
 重新安装python,加上这个 –with-ssl  
 ./configure –prefix=/usr/local/Python3.71 –with-ssl  
 make&make install  
 开始校验:  
    
    
  导入ssl模块没有报错即可  
 方法二:  
 1.编译安装OpenSSL 1.0.2j版本并重新配置环境变量  
 下载OpenSSL源码包:(在/usr/local/python3下执行) wget http://www.openssl.org/source/openssl-1.0.2j.tar.gz  
 解压缩,编译安装: tar -zxvf openssl-1.0.2j.tar.gz cd openssl-1.0.2j  
 # 修改编译参数,no-zlib 不需要zlib
./config --prefix=/usr/local/python3/openssl-1.0.2j no-zlib  
 make && make install  
 2.重新编译安装python3.6.2  
 安装Python3.6的前期准备  
 安装前更新yum源  
 安装python3所需依赖:  
 yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel libffi-devel gcc make  
 然后重新编译python3.6.2:  
 tar -zxvf Python-3.6.2.tgz cd Python-3.6.2 ./configure --prefix=/usr/local/python3  
 在这一步之后,先不要着急运行make命令。先修改源码目录 Python-3.6.2/Modules/Setup 文件:  
 [root@localhost ~]  
 # Socket module helper for socket(2) #_socket socketmodule.c  
 # Socket module helper for SSL support; you must comment out the other # socket line above, and possibly edit the SSL variable: SSL=/usr/local/lab/openssl-1.0.2j/ #取消这一行的注释,并将原来的/usr/local/ssl改为我们新安装的openssl目录:/usr/local/python3/openssl-1.0.2j/ _ssl _ssl.c \ #取消这一行的注释 -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \ #取消这一行的注释 -L$(SSL)/lib -lssl -lcrypto #取消这一行的注释  
 最后重新编译安装python3:  
 make& make install   
 此时发现安装完后pip3也进行了安装,大功告成。  
 再次导包,成功安装  
    
    
    
 入坑完毕。  
 参考文档:http://www.yueguangzu.net/?p=1677  
        https://blog.csdn.net/reblue520/article/details/94072018  
        https://www.jb51.net/article/166688.htm  
          
    
  |