Java自学者论坛

 找回密码
 立即注册

手机号码,快捷登录

恭喜Java自学者论坛(https://www.javazxz.com)已经为数万Java学习者服务超过8年了!积累会员资料超过10000G+
成为本站VIP会员,下载本站10000G+会员资源,会员资料板块,购买链接:点击进入购买VIP会员

JAVA高级面试进阶训练营视频教程

Java架构师系统进阶VIP课程

分布式高可用全栈开发微服务教程Go语言视频零基础入门到精通Java架构师3期(课件+源码)
Java开发全终端实战租房项目视频教程SpringBoot2.X入门到高级使用教程大数据培训第六期全套视频教程深度学习(CNN RNN GAN)算法原理Java亿级流量电商系统视频教程
互联网架构师视频教程年薪50万Spark2.0从入门到精通年薪50万!人工智能学习路线教程年薪50万大数据入门到精通学习路线年薪50万机器学习入门到精通教程
仿小米商城类app和小程序视频教程深度学习数据分析基础到实战最新黑马javaEE2.1就业课程从 0到JVM实战高手教程MySQL入门到精通教程
查看: 652|回复: 0

centos6.8安装python3.7.3报错Can't connect to HTTPS URL because the SSL module is not available问题解决

[复制链接]
  • TA的每日心情
    奋斗
    2024-4-6 11:05
  • 签到天数: 748 天

    [LV.9]以坛为家II

    2034

    主题

    2092

    帖子

    70万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    积分
    705612
    发表于 2021-7-18 17:00:53 | 显示全部楼层 |阅读模式
    环境:CentOS release 6.8 (Final)
    
    
    # 直接编译python3.7在使用pip3安装依赖的时候报错:
    
    Can't connect to HTTPS URL because the SSL module is not available.
    
    
    解决方法:
    
    1.编译安装OpenSSL 1.0.2j版本并重新配置环境变量
    
    下载OpenSSL源码包:
    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
    ./config --prefix=/usr/local/lab/openssl-1.0.2j shared zlib
    make && make install
    
    
    2.编译安装Python3,使用自定义的OpenSSL
    
    下载Python3.7.3源码包:
    
    wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tgz
    
    解压缩,编译安装:
    
    tar -zxvf Python-3.7.3.tgz
    cd Python-3.7.3
    ./configure --prefix=/usr/local/python373
    
    在这一步之后,先不要着急运行make命令。先修改源码目录 Python-3.7.3/Modules/Setup 文件:
    
    # 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/lab/openssl-1.0.2j/
    _ssl _ssl.c \     #取消这一行的注释
    -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \      #取消这一行的注释
    -L$(SSL)/lib -lssl -lcrypto      #取消这一行的注释
    
    # The crypt module is now disabled by default because it breaks builds
    # on many systems (where -lcrypt is needed), e.g. Linux (I believe).
    
    #_crypt _cryptmodule.c # -lcrypt    # crypt(3); needs -lcrypt on some systems
    
    
    修改完成以后,还需要创建两个指向动态链接库的软链接文件:
    ln -s /usr/local/lab/openssl-1.0.2j/lib/libssl.so.1.0.0 /usr/lib64/libssl.so.1.0.0
    ln -s /usr/local/lab/openssl-1.0.2j/lib/libcrypto.so.1.0.0 /usr/lib64/libcrypto.so.1.0.0
    
    
    最后编译并安装:
    make && make install
    
    # 创建软连接
    ln -s /usr/local/python373/bin/pip3 /usr/local/bin/pip3
    ln -s /usr/local/python373/bin/python3 /usr/local/bin/python3
    
    # 安装软件继续报错:
    [root@srv3:/usr/local]# pip3 install requests
    Collecting requests
    /usr/local/python373/bin/python3.7: symbol lookup error: /usr/local/python373/bin/python3.7: undefined symbol: SSL_CTX_get0_param
    
    
    # 找了各自资料发现都无法解决这个问题,问题很可能就出在openssl上
    
    undefined symbol: SSL_CTX_get0_param 这个函数就是zlib源码中的函数,于是重新编译openssl
    
    
    1.清理之前安装的openssl
    rm -rf /usr/local/src/openssl-1.0.2j    # 清理源码
    rm -rf /usr/local/lab/openssl-1.0.2j    # 清理安装程序
    
    tar -zxvf openssl-1.0.2j.tar.gz
    cd openssl-1.0.2j
    # 修改编译参数,no-zlib 不需要zlib
    ./config --prefix=/usr/local/lab/openssl-1.0.2j no-zlib
    make && make install
    
    
    2.重新编译安装Python3.7.3
    
    # 清理源码目录和已经按照的目录
    rm -rf /usr/local/src/Python-3.7.3
    rm -rf /usr/local/python373
    
    # 再次解压编译安装
    tar -zxvf Python-3.7.3.tgz
    cd Python-3.7.3
    ./configure --prefix=/usr/local/python373
    
    在这一步之后,先不要着急运行make命令,先修改源码目录 Python-3.7.3/Modules/Setup 文件:
    
    # 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/lab/openssl-1.0.2j/
    _ssl _ssl.c \     #取消这一行的注释
    -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \      #取消这一行的注释
    -L$(SSL)/lib -lssl -lcrypto      #取消这一行的注释
    
    # The crypt module is now disabled by default because it breaks builds
    # on many systems (where -lcrypt is needed), e.g. Linux (I believe).
    
    #_crypt _cryptmodule.c # -lcrypt    # crypt(3); needs -lcrypt on some systems
    
    
    最后编译并安装:
    make && make install
    
    # 再次pip3安装依赖就不会报错了
    [root@srv3:/usr/local/src/Python-3.7.3]# pip3 install requests
    Collecting requests
      Downloading https://files.pythonhosted.org/packages/51/bd/23c926cd341ea6b7dd0b2a00aba99ae0f828be89d72b2190f27c11d4b7fb/requests-2.22.0-py2.py3-none-any.whl (57kB)
        100% |████████████████████████████████| 61kB 14.1MB/s 
    Collecting certifi>=2017.4.17 (from requests)
      Downloading https://files.pythonhosted.org/packages/69/1b/b853c7a9d4f6a6d00749e94eb6f3a041e342a885b87340b79c1ef73e3a78/certifi-2019.6.16-py2.py3-none-any.whl (157kB)
        100% |████████████████████████████████| 163kB 23.3MB/s 
    Collecting idna<2.9,>=2.5 (from requests)
      Downloading https://files.pythonhosted.org/packages/14/2c/cd551d81dbe15200be1cf41cd03869a46fe7226e7450af7a6545bfc474c9/idna-2.8-py2.py3-none-any.whl (58kB)
        100% |████████████████████████████████| 61kB 19.8MB/s 
    Collecting chardet<3.1.0,>=3.0.2 (from requests)
      Downloading https://files.pythonhosted.org/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whl (133kB)
        100% |████████████████████████████████| 143kB 23.9MB/s 
    Collecting urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 (from requests)
      Downloading https://files.pythonhosted.org/packages/e6/60/247f23a7121ae632d62811ba7f273d0e58972d75e58a94d329d51550a47d/urllib3-1.25.3-py2.py3-none-any.whl (150kB)
        100% |████████████████████████████████| 153kB 24.8MB/s 
    Installing collected packages: certifi, idna, chardet, urllib3, requests
    Successfully installed certifi-2019.6.16 chardet-3.0.4 idna-2.8 requests-2.22.0 urllib3-1.25.3

     

    哎...今天够累的,签到来了1...
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|手机版|小黑屋|Java自学者论坛 ( 声明:本站文章及资料整理自互联网,用于Java自学者交流学习使用,对资料版权不负任何法律责任,若有侵权请及时联系客服屏蔽删除 )

    GMT+8, 2024-5-15 06:03 , Processed in 0.066314 second(s), 29 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2021, Tencent Cloud.

    快速回复 返回顶部 返回列表