Python 3 No module named '_ssl'

主宰稳场 提交于 2020-01-14 13:14:34

问题


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


回答1:


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.




回答2:


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-dev openssl-devel sqlite-devel bzip2-devel libffi libffi-devel gcc gcc-c++
wget 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


来源:https://stackoverflow.com/questions/44106399/python-3-no-module-named-ssl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!