How to fix "ssl module in Python is not available" in CentOs
Asked Answered
C

10

30

New Python 3.7.1 installation on GoDaddy VPS CentOs 7. Attempt pip3 install virtualenv or python 3 -m pip install virtualenv and get:

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

openssl-devel installed and up to date

This question has been asked and answered many times, but the solutions I've found have not solved my problem. Thank you all!

I tried the CentOs and Linux-based solutions in the following:

"SSL module in Python is not available" when installing package with pip3 # To allow for building python ssl libs yum install openssl-devel # Download the source of any python version cd /usr/src wget https://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" and 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

Concavoconvex answered 11/6, 2019 at 22:24 Comment(0)
S
46

This works for me on CentOS 7.9 with Python 3.10.9 based on https://bugs.python.org/issue47201

This edits configure instead of Modules/Setup:

sudo yum install -y epel
sudo yum install -y openssl11-devel
wget https://www.python.org/ftp/python/3.10.9/Python-3.10.9.tgz
tar zxvf Python-3.10.9.tgz
cd Python-3.10.9
sed -i 's/PKG_CONFIG openssl /PKG_CONFIG openssl11 /g' configure
./configure --enable-optimizations
sudo make altinstall
# The following should run without errors if SSL was properly compiled
python3.10 -m ssl

If a more recent version of Python works for you, then perhaps it may be useful to others to leave a comment about it.

Swarey answered 13/1, 2023 at 21:17 Comment(8)
This worked well on Centos7Berkie
Worked for me only after using epel-release.noarch rather than epelAerography
I got No module named '_ssl' when running the last lineLegist
This works on Amazon Linux 2, minus installing epel.Prodigy
@Legist I was getting the same error but I wasn't running all of the lines, I skipped some because I thought I had already installed the packages. I redid all the lines and it worked. I'm using Amazon Linux 2Halfon
This works also on Centos 7.9 and Python3.12. Of cource you have to install openssl1.1.1 first gist.github.com/Bill-tran/5e2ab062a9028bf693c934146249e68cTemptation
For optimizations option --enable-optimizations in CentOS 7 see here: https://mcmap.net/q/81002/-how-to-succesfully-compile-python-3-xTonality
I also had this error: https://mcmap.net/q/82170/-python-build-error-in-centos-7-0 and other errors. Yo should install yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tkinter tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-develTonality
C
17

Here is a working solution for Python 3.7.9 and 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

In /usr/src/Python-3.7.9/Modules/Setup.dist, uncomment these 4 lines:

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

And finally:

./configure --enable-optimizations
make altinstall
Cautionary answered 20/10, 2020 at 14:51 Comment(4)
Thank You, Now I can use a on centos8 a most recent version of Python than the 3.6.8Korean
I don't seem to find Setup.dist in python 3.10.5.. Do we have fix for it?Tokharian
There is no /usr/src/Python-3.7.9/Modules/Setup.dist file.Adsorbent
Also, look in /usr/src/Python-3.x.x/Modules/Setup for other versions of PythonApiculate
N
12

I have seen this error when the version of openssl is incompatible. This is more likely when you're installing a newer Python (such as 3.7.2) on a not-as-recent version of the Linux system.

I would check to see what version of SSL libraries are expected with this version of Python and if necessary, install them locally.

This is a basic description of building the SSL libraries: DreamHost instructions for Installing Local OpenSSL Version

You will want to build Python again with the following option added to your invocation of ./config:

--with-openssl=/path/to/your/local/install
Neap answered 28/10, 2019 at 22:21 Comment(1)
This worked well on a Red Hat 8.4 with openssl 1.1.1k and python 3.7.11Menses
C
5

Minor correction to a prev answer by Kevin Lemaire

Here is a working solution for Python 3.7.9 and 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

In Modules/Setup, uncomment these 4 lines: <<< minor correction

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

And finally:

./configure --enable-optimizations
make altinstall
Cotinga answered 27/1, 2022 at 19:26 Comment(2)
This works for CENTOs 7 and Python 3.8.14, thank you.Carlow
this for my kali linux unstable version I needed multiple python versions and got it working installing libbz2-dev openssl libssl-dev liblzma-dev and using that SSL path. then used sudo make altinstall and now working. to test use python3.10 -c "import ssl", it should get no errorsPaten
C
4

Please read this article

Basically you need to install openssl first and uncomment ssl related lines in Modules/Setup file in python source code before to make install. This worked to me on installing Python 3.8.

Christychristye answered 10/2, 2020 at 19:19 Comment(1)
This actually solved the issue. Just uncomment the lines using that default path for ssl (/usr/local/ssl). then install libbz2-dev openssl libssl-dev liblzma-dev if they are missing and lastly go ahead and sudo make altinstall. Glad this worked, thank you.Paten
R
3

I solve the problem by Matt's answer.

For those who can not find the package epel:

$ yum install -y epel
......
No package epel available.

$ yum search epel
......
================================ N/S matched: epel ================================
epel-release.noarch : Extra Packages for Enterprise Linux repository configuration

$ yum install epel-release.noarch
Ridglea answered 31/5, 2023 at 12:59 Comment(0)
S
1

For me what worked on CentOS 7.9 and using the following guide: https://bugs.python.org/issue47201

Essentially after downloading Python 3.11.3 and unpacking it, from its folder I ran:

sudo yum install -y epel
sudo yum install -y openssl11-devel
sed -i 's/PKG_CONFIG openssl /PKG_CONFIG openssl11 /g' configure

Then I ran:

./configure --enable-optimizations
make altinstall

This successfully installed python3.11 and pip3.11 with the ssl properly configured and the error was not shown anymore.

Snakeroot answered 3/8, 2023 at 13:1 Comment(0)
S
0

I know this isn't the answer for centOS, but for the other poor souls like me who couldn't find the answer elsewhere, the accepted answer works with the following modifications on an ubuntu install:

sudo apt install libssl-dev liblzo2-dev libpam0g-dev
sed -i 's/PKG_CONFIG openssl /PKG_CONFIG openssl11 /g' configure
./configure --enable-optimizations
sudo make altinstall

In my case, I'd altinstalled python3.7 and was hitting the same error as reported in this ticket.

Lastly wanted to add that, these steps will repair your existing (alt)install. You don't need to (nor should you, from what I've read) clean up a python install unless you really know what you're doing.

Cheers

Strontia answered 19/10, 2023 at 0:43 Comment(0)
U
-1

Taking inspiration from the two answers on this thread, downloading and extracting OpenSSL 1.1.1o and then running the following sequence of commands solved the problem for me.

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
./configure --enable-optimizations --with-openssl=/path/to/your/local/install
make install
Underbody answered 13/6, 2022 at 9:24 Comment(1)
What is /path/to/your/local/install? Path to OpenSSL sources? To OpenSSL binaries?Adsorbent
C
-7

Solution: Python 3.6.2 instead of 3.7.1

Concavoconvex answered 13/6, 2019 at 1:54 Comment(1)
While this probably fixes the issue, I wouldn't call it a solution. There are features of 3.7 that aren't included in 3.6.Bookish

© 2022 - 2024 — McMap. All rights reserved.