Python 3 No module named '_ssl'
Asked Answered
N

3

5

The Problem

While I run you python3 application, it shows

  File "/usr/local/lib/python3.6/ssl.py", line 101, in <module>
import _ssl             # if we can't import it, let the error propagate
ModuleNotFoundError: No module named '_ssl'

What I've tried

install the dependencies

yum install openssl-devel

I also edited the setup.py file and recomplie python3

# Detect SSL support for the socket module (via _ssl)
search_for_ssl_incs_in = [
                          '/usr/local/ssl/include',
                          '/usr/local/include/openssl', #I've added this line
                          '/usr/contrib/ssl/include/'
                         ]

I've complied the openssl with the path configuration

#tar -xzvf openssl-***.tar.gz

#./config --prefix=/usr/local --openssldir=/usr/local/openssl

#make & make install

CentOS 7

Python 3.6

Neck answered 22/5, 2017 at 6:55 Comment(4)
Can you try compiling with --with-ssl option?Osmious
the --with-ssl is out of dateNeck
@Lanston: I am facing the same issue...how had you fixed it?Shorter
@Neck i am facing the same issue please help me how you solved itAggressor
M
6

I found some solution:

if you use centos,try:

s1

yum install openssl-devel -y

then when you compile, append --with-ssl,just like this

./configure prefix=/usr/local/share/python3 --with-ssl

s2

-- install depend library, make share compile is fluent

yum install -y zlib zlib-devel openssl-devel sqlite-devel bzip2-devel libffi libffi-devel gcc gcc-c++

(ubuntu)sudo apt-get install libz-dev

wget --no-check-certificate http://www.openssl.org/source/openssl-1.1.1.tar.gz
tar -zxvf openssl-1.1.1.tar.gz
cd openssl-1.1.1
./config --prefix=$HOME/openssl shared zlib
make && make install

-- configure shared ld library path so that compile can find it

echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/openssl/lib" >> $HOME/.bash_profile
source $HOME/.bash_profile

(zsh user has some different with .zsh_profile) -- compile with openssl path

 ./configure prefix=/usr/local/share/python3 --with-openssl=$HOME/openssl
Majunga answered 21/5, 2019 at 4:24 Comment(0)
A
4

I faced the same issue, I installed python from source and didn't enabled ssl option while compiling. So I find the solution in the following article. You need to find ssl section Modules/Setup.dist and uncomment that section. Hope this will help someone.

Ankara answered 21/11, 2017 at 18:4 Comment(0)
L
0

For those who coming here having Ubuntu: try apt install libssl-dev

Lor answered 12/8, 2023 at 16:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.