【问题标题】:How to fix "ssl module in Python is not available" in CentOs如何在 CentOs 中修复“Python 中的 ssl 模块不可用”
【发布时间】:2019-10-26 09:19:57
【问题描述】:

在 GoDaddy VPS CentOs 7 上安装新的 Python 3.7.1。 尝试 pip3 install virtualenv 或 python 3 -m pip install virtualenv 并获取:

pip 配置了需要 TLS/SSL 的位置,但是 Python 中的 ssl 模块不可用。

openssl-devel 已安装并且是最新的

这个问题已经被问过很多次了,但是我找到的解决方案并没有解决我的问题。 谢谢大家!

我尝试了以下基于 CentO 和 Linux 的解决方案:

"SSL module in Python is not available" when installing package with pip3 # 允许构建 python ssl 库 百胜安装 openssl-devel # 下载any python版本的源码 cd /usr/src wgethttps://www.python.org/ftp/python/3.7.1/Python-3.7.1.tar.xz tar xf Python-3.7.1.tar.xz cd Python-3.7.1

  # Configure the build w/ your installed libraries
  ./configure

  # Install into /usr/local/bin/python3.6, don't overwrite global python bin
  make altinstall

Trying to install packages with Python 3.7.2 pip causes TSL/SSL errors

"SSL module in Python is not available" when installing package with pip3

pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available

yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel

pip cannot confirm SSL certificate: SSL module is not available

"ssl module in Python is not available"pip cannot confirm SSL certificate: SSL module is not available

  `uncommented suggestions for CentOs
  make install failed:
    gcc -pthread -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall    -std=c99 -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration   -I. -I./Include     -DUSE_SSL -I/include -I/include/openssl -c ./Modules/_ssl.c -o Modules/_ssl.o
    ./Modules/_ssl.c:74:6: error: #error "libssl is too old and does not support X509_VERIFY_PARAM_set1_host()"
    ./Modules/_ssl.c: In function ‘_ssl_configure_hostname’:
    ./Modules/_ssl.c:861: error: implicit declaration of function ‘SSL_get0_param’
    ./Modules/_ssl.c:861: warning: initialization makes pointer from integer without a cast
    ./Modules/_ssl.c:863: error: implicit declaration of function ‘X509_VERIFY_PARAM_set1_host’
    ./Modules/_ssl.c:869: error: implicit declaration of function ‘X509_VERIFY_PARAM_set1_ip’
    ./Modules/_ssl.c: In function ‘_ssl__SSLContext_impl’:
    ./Modules/_ssl.c:2988: error: ‘X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS’ undeclared (first use in this function)
    ./Modules/_ssl.c:2988: error: (Each undeclared identifier is reported only once
    ./Modules/_ssl.c:2988: error: for each function it appears in.)
    ./Modules/_ssl.c:3093: error: implicit declaration of function ‘SSL_CTX_get0_param’
    ./Modules/_ssl.c:3093: warning: assignment makes pointer from integer without a cast
    ./Modules/_ssl.c:3099: error: implicit declaration of function ‘X509_VERIFY_PARAM_set_hostflags’
    ./Modules/_ssl.c: In function ‘get_verify_flags’:
    ./Modules/_ssl.c:3397: warning: assignment makes pointer from integer without a cast
    ./Modules/_ssl.c: In function ‘set_verify_flags’:
    ./Modules/_ssl.c:3410: warning: assignment makes pointer from integer without a cast
    ./Modules/_ssl.c: In function ‘set_host_flags’:
    ./Modules/_ssl.c:3573: warning: assignment makes pointer from integer without a cast
    make: *** [Modules/_ssl.o] Error 1`

https://www.tomordonez.com/pip-install-ssl-module-python-is-not-available.html

【问题讨论】:

    标签: python centos


    【解决方案1】:

    Kevin Lemaire 对上一个答案的小幅更正

    这是适用于 Python 3.7.9 和 CentOS 7.8.2003 的有效解决方案:

    su - root
    yum install gcc openssl-devel bzip2-devel libffi-devel zlib-devel -y
    cd /usr/src
    wget https://www.python.org/ftp/python/3.7.9/Python-3.7.9.tgz
    tar xzf Python-3.7.9.tgz
    cd Python-3.7.9
    

    在 Modules/Setup 中,取消注释这 4 行:

    SSL=/usr/local/ssl
    _ssl _ssl.c \
        -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
        -L$(SSL)/lib -lssl -lcrypto
    

    最后:

    ./configure --enable-optimizations
    make altinstall
    

    【讨论】:

      【解决方案2】:

      这是适用于 Python 3.7.9 和 CentOS 7.8.2003 的有效解决方案:

      su - root
      yum install gcc openssl-devel bzip2-devel libffi-devel zlib-devel -y
      cd /usr/src
      wget https://www.python.org/ftp/python/3.7.9/Python-3.7.9.tgz
      tar xzf Python-3.7.9.tgz
      cd Python-3.7.9
      

      /usr/src/Python-3.7.9/Modules/Setup.dist 中,取消注释这 4 行:

      SSL=/usr/local/ssl
      _ssl _ssl.c \
          -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
          -L$(SSL)/lib -lssl -lcrypto
      

      最后:

      ./configure --enable-optimizations
      make altinstall
      

      【讨论】:

      • 谢谢,现在我可以在 centos8 上使用比 3.6.8 最新版本的 Python 了
      【解决方案3】:

      请阅读this article

      基本上你需要先安装openssl,并在安装之前在python源代码的Modules/Setup文件中取消注释ssl相关行。 这对我安装 Python 3.8 很有用。

      【讨论】:

        【解决方案4】:

        我在openssl的版本不兼容时看到了这个错误。当您在不是最新版本的 Linux 系统上安装较新的 Python(例如 3.7.2)时,这种情况更有可能发生。

        我会检查这个版本的 Python 需要什么版本的 SSL 库,如有必要,在本地安装它们。

        这是构建 SSL 库的基本描述:DreamHost instructions for Installing Local OpenSSL Version

        您将需要在调用 ./config 时添加以下选项来再次构建 Python:

        --with-openssl=/path/to/your/local/install
        

        【讨论】:

        • 这在带有 openssl 1.1.1k 和 python 3.7.11 的 Red Hat 8.4 上运行良好
        【解决方案5】:

        解决方案:Python 3.6.2 而不是 3.7.1

        【讨论】:

        • 虽然这可能会解决问题,但我不会称其为解决方案。 3.6 中没有包含 3.7 的一些功能。
        猜你喜欢
        • 1970-01-01
        • 2022-07-25
        • 2020-02-05
        • 1970-01-01
        • 2019-12-13
        • 2020-05-02
        • 1970-01-01
        • 1970-01-01
        • 2011-07-19
        相关资源
        最近更新 更多