pythonpython-3.xssl-certificatecentos7python-ssl

CentOs7: ssl module in Python is not available


I am on CentOS Linux release 7.9.2009 (Core), installed python3.10.12 from source using the following script

sudo yum update

sudo yum groupinstall "Development Tools"
sudo yum install zlib-devel bzip2-devel \
  openssl-devel ncurses-devel sqlite-devel \
  readline-devel tk-devel gdbm-devel \
  libffi-devel xz-devel


wget https://www.python.org/ftp/python/3.10.12/Python-3.10.12.tgz


tar -xvf Python-3.10.12.tgz

./configure --enable-optimizations

make

sudo make altinstall


Python 3.10.12 (main, Jul  8 2023, 16:54:43) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information


sudo ln -s /usr/local/bin/python3.10 /usr/local/bin/python3

But, when trying pip, I got this error

There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/tutor/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping

Tried to list the ssl modules installed for python3, and got this enter image description here

Also, when trying

python3.10 -m ssl

I got

ModuleNotFoundError: No module named '_ssl'

I found some answer that suggests adding --with-ssl option while building, and another answer that deosn't use this option at all. How can I solve this?


Solution

  • If you look at your ./configure output, you will see:

    checking for --with-openssl-rpath...
    checking whether OpenSSL provides required APIs... no
    checking for --with-ssl-default-suites... python
    

    So the configure script is failing to detect necessary support in OpenSSL. If we look at config.log, we find:

    configure:17849: checking whether OpenSSL provides required APIs
    configure:17895: gcc -pthread -o conftest  -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration -fvisibility=hidden       conftest.c -lcrypt -lpthread -ldl  -lutil -lm -lssl -lcrypto   >&5
    conftest.c:410:2: error: #error "OpenSSL >= 1.1.1 is required"
     #error "OpenSSL >= 1.1.1 is required"
    

    And there's your problem; Python 3.10 requires OpenSSL version 1.1.1 or later, and CentOS 7 only provides 1.0.2.

    If you want ssl support in your custom built Python, you'll need to first build a recent version of OpenSSL and install it somewhere on your system, and then provide configure with appropriate arguments to find it.


    Alternately: