There are a lot of articles on the Internet about how to solve the failure of Python3.7 import _SSL module, but most of the actual operation is not successful. The following method can be used in a practical test.
First, install dependencies
OpenSSL or Libressl (either optional) is required to install the SSL module. OpenSSL is installed in version 1.0.1, which does not meet the requirements of Python3.7. The version requirements for the SSL library are as follows:
openssl > = 1.0.2 libressl & gt; = 2.6.4
My working environment:
14.04 Python3.7.3 Ubutun download link: https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tgz
Download and install Libressl
Website: https://www.libressl.org/, download link: https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-2.9.1.tar.gz./config – prefix =/usr/local/SSL make sudo make intallmv/usr/bin/openssl/usr/bin/openssl. Bak (if not installed SSL before, /usr/include/openssl.bak /usr/include/openssl.bak This step can be skipped) ln -s/usr/local/SSL/bin/openssl/usr/bin/openssl ln -s/usr/local/SSL/include/openssl/usr/include/openssl in/etc/ld. So. Conf., d directory to create libressl – 2.9.1. Conf file, add/usr/local/SSL/libsudo ldconfig
Install Python3.7
Configure environment variables
Export LDFLAGS = “-l/usr/local/SSL/lib”
export CPPFLAGS = “-i/usr/local/SSL/include”
export PKG_CONFIG_PATH = “/ usr/local/SSL/lib/pkgconfig”
Unzip the Python installation package and execute the configure file:
./configure — enable – Shared
Check that the SSL configuration is working
Verifies that the SSL module was successfully installed in /usr/local/bin/python3.7
3. Other errors
Failed to compile the SSL module
Solutions:
Go to the libressl compilation directory libressl-2.9.1
Sudo cp SSL/libs/libssl. So the 47.0.5 – gnu/Linux/lib/x86_64 –
sudo cp crypto/libs/libcrypto. So the 45.0.4/lib/x86_64 – – the gnu/Linux
Sudo ln-s /lib/x86_64-linux-gnu/libcrypto.so.47.0.5 /lib/x86_64-linux-gnu/libcrypto.so.47
sudo ln-s /lib/x86_64-linux-gnu/libcrypto.so.45.0.4 /lib/x86_64-linux-gnu/libcrypto.so.45
recompile
Failed to compile the _ctypes module
Sudo apt-get install libffi-dev, install libffi-dev, install libffi-dev
First, install dependencies
OpenSSL or Libressl (either optional) is required to install the SSL module. OpenSSL is installed in version 1.0.1, which does not meet the requirements of Python3.7. The version requirements for the SSL library are as follows:
openssl > = 1.0.2 libressl & gt; = 2.6.4
My working environment:
14.04 Python3.7.3 Ubutun download link: https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tgz
Download and install Libressl
Website: https://www.libressl.org/, download link: https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-2.9.1.tar.gz./config – prefix =/usr/local/SSL make sudo make intallmv/usr/bin/openssl/usr/bin/openssl. Bak (if not installed SSL before, /usr/include/openssl.bak /usr/include/openssl.bak This step can be skipped) ln -s/usr/local/SSL/bin/openssl/usr/bin/openssl ln -s/usr/local/SSL/include/openssl/usr/include/openssl in/etc/ld. So. Conf., d directory to create libressl – 2.9.1. Conf file, add/usr/local/SSL/libsudo ldconfig
Install Python3.7
Configure environment variables
Export LDFLAGS = “-l/usr/local/SSL/lib”
export CPPFLAGS = “-i/usr/local/SSL/include”
export PKG_CONFIG_PATH = “/ usr/local/SSL/lib/pkgconfig”
Unzip the Python installation package and execute the configure file:
./configure — enable – Shared
Check that the SSL configuration is working
Verifies that the SSL module was successfully installed in /usr/local/bin/python3.7
3. Other errors
Failed to compile the SSL module
Solutions:
Go to the libressl compilation directory libressl-2.9.1
Sudo cp SSL/libs/libssl. So the 47.0.5 – gnu/Linux/lib/x86_64 –
sudo cp crypto/libs/libcrypto. So the 45.0.4/lib/x86_64 – – the gnu/Linux
Sudo ln-s /lib/x86_64-linux-gnu/libcrypto.so.47.0.5 /lib/x86_64-linux-gnu/libcrypto.so.47
sudo ln-s /lib/x86_64-linux-gnu/libcrypto.so.45.0.4 /lib/x86_64-linux-gnu/libcrypto.so.45
recompile
Failed to compile the _ctypes module
Sudo apt-get install libffi-dev, install libffi-dev, install libffi-dev