Python3 ImportError: No module named _ssl [How to Solve]

 

The system does not have openssl, manually install openssl
1.Download openssl from http://www.openssl.org/source/openssl-1.0.2a.tar.gz
2.Install.
tar -xzvf openssl-1.0.2a.tar.gz
. /config --prefix=/usr/local --openssldir=/usr/local/openssl
make && make install
 
3. Find the include directory in the /usr/local directory
Find the path /usr/local/include, which will be used in the next steps
There are openssl files under this directory
[[email protected] local]# pwd
/usr/local
[[email protected] local]# ll 
drwxr-xr-x. 2 root  root 4096 11月 13 13:59 bin
drwxr-xr-x. 3 root  root 4096 11月 13 13:59 include
drwxr-xr-x. 2 root  root 4096 11月  1 2011 lib
drwxr-xr-x. 4 root  root 4096 11月 13 13:59 lib64
drwxr-xr-x. 2 root  root 4096 11月  1 2011 libexec
drwxr-xr-x. 2 root  root 4096 11月  1 2011 sbin
 
 
4.In the python3.x source file, find the Setup.dist file and modify it as follows so that the openssl library you just installed can be found when you compile Python
1) Find the SSL related configuration
#SSL=/usr/local/ssl
#_ssl _ssl.c \
#        -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
#        -L$(SSL)/lib -lssl -lcrypto
 
2) (Since openssl is installed in the lib64 and include directories in the /usr/local directory, not in the /usr/local/ssl directory,) remove the comments and modify the path as follows
SSL=/usr/local
_ssl _ssl.c \
        -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
        -L$(SSL)/lib64 -lssl -lcrypto

5 To re-install and compile python 3.x
. /configure --prefix=/usr/local/xxxx
make && make install

6 Try to see if it is available

[[email protected] Python-3.6.5]# python3
Python 3.6.5 (default, Mar 22 2019, 11:36:59) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
>>> 

Similar Posts: