Package Installation via PIP error - Giving ModuleNotFoundError: No module named '_ssl'

Hello
I have installed python 3.8.13. Pip version is 22.0.4

But pip is not working. It gives this SSL error whenever I use pip.

I even have installed the OpenSSL by following this method

Still getting these errors.

Need Guidance over here.

Thank you.

Maybe worth trying…

pip3 install pandas

Saad said:

“But pip is not working. It gives this SSL error whenever I use pip.”

How do you expect to pip install pandas when pip is not working?

If pip3 install ... succeeds when python3-m pip install ... fails, that can only mean that pip3 is running a different Python interpreter, which won’t help Saad.

The problem here is that Saad’s Python is installed without support for SSL. That’s why he gets an error about the _ssl module being missing.

I think that the only way to fix this is to re-install Python with SSL:

  1. Maybe use a pre-packaged Python, such as Anaconda?

  2. Find out how to setup SSL on your machine, and then reinstall Python.

How did you install Python in the first place? What OS are you running?

On a Red Hat Linux system, I needed to install the following packages using the system package manager, dnf, before I could build Python correctly:

  • readline
  • sqlite
  • tk
  • Open SSL
  • lzma

which I did using the shell command:

sudo dnf install readline-devel sqlite-devel tk-devel openssl-devel lzma-devel

Notice it is not enough to have the openssl system package installed, you also need the openssl-devel package. On Ubuntu system, I think that is called openssl-dev.

Then I ran the usual command to build Python from source:

./configure
make
make test
sudo make altinstall

But of course this will depend on your operating system and how you installed Python.

1 Like

Hi
I am working on AD9361Z7035 breakout board. OS is linaro 14.04. Processor is ARMv7l. I am facing some issues here. Need help.

Here I want to install an updated pip. Which I did i.e. (pip 22.0.4 from /usr/local/lib/python3.8/site-packages/pip (python 3.8)). But it is still giving the above mentioned SSL error.

root@analog:~# openssl version
OpenSSL 1.0.1i-dev xx XXX xxxx

I followed this video Python Install - compile from source with SSL module, pip TLS/ SSL - Debian, Ubuntu - YouTube

I build the python for SSL.

checking for %zd printf() format support... yes
checking for socklen_t... yes
checking for broken mbstowcs... no
checking for --with-computed-gotos... no value specified
checking whether gcc -pthread supports computed gotos... yes
checking for build directories... done
checking for -O2... yes
checking for glibc _FORTIFY_SOURCE/memmove bug... no
checking for stdatomic.h... no
checking for GCC >= 4.7 __atomic builtins... yes
checking for ensurepip... upgrade
checking if the dirent structure of a d_type field... yes
checking for the Linux getrandom() syscall... no
checking for the getrandom() function... no
checking for library containing shm_open... -lrt
checking for sys/mman.h... (cached) yes
checking for shm_open... yes
checking for shm_unlink... yes
checking for openssl/ssl.h in /usr... yes
checking whether compiling and linking against OpenSSL works... yes
checking for X509_VERIFY_PARAM_set1_host in libssl... no
checking for --with-ssl-default-suites... python
configure: creating ./config.status
config.status: creating Makefile.pre
config.status: creating Misc/python.pc
config.status: creating Misc/python-embed.pc
config.status: creating Misc/python-config.sh
config.status: creating Modules/ld_so_aix
config.status: creating pyconfig.h
config.status: pyconfig.h is unchanged
creating Modules/Setup.local
creating Makefile

Here this should be yes.
X509_VERIFY_PARAM_set1_host in libssl… no

Moving further on installing it, I got this error.

root@analog:/usr/src/Python-3.8.13# sudo make altinstall
gcc -pthread -c -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall    -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration  -I./Include/internal  -I. -I./Include    -DPy_BUILD_CORE -o Programs/python.o ./Programs/python.c
gcc -pthread -c -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall    -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration  -I./Include/internal  -I. -I./Include    -DPy_BUILD_CORE -o Parser/acceler.o Parser/acceler.c
gcc -pthread -c -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall    -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration  -I./Include/internal  -I. -I./Include    -DPy_BUILD_CORE -o Parser/grammar1.o Parser/grammar1.c
gcc -pthread -c -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall    -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration  -I./Include/internal  -I. -I./Include    -DPy_BUILD_CORE -o Parser/listnode.o Parser/listnode.c
gcc -pthread -c -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall    -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration  -I./Include/internal  -I. -I./Include    -DPy_BUILD_CORE -o Parser/node.o Parser/node.c
gcc -pthread -c -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall    -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration  -I./Include/internal  -I. -I./Include    -DPy_BUILD_CORE -o Parser/parser.o Parser/parser.c
gcc -pthread -c -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall    -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration  -I./Include/internal  -I. -I./Include    -DPy_BUILD_CORE -o Parser/token.o Parser/token.c
gcc -pthread -c -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall    -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration  -I./Include/internal  -I. -I./Include    -DPy_BUILD_CORE -o Parser/myreadline.o Parser/myreadline.c
gcc -pthread -c -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall    -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration  -I./Include/internal  -I. -I./Include    -DPy_BUILD_CORE -o Parser/parsetok.o Parser/parsetok.c
gcc -pthread -c -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall    -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration  -I./Include/internal  -I. -I./Include    -DPy_BUILD_CORE -o Parser/tokenizer.o Parser/tokenizer.c


cc1: some warnings being treated as errors
make: *** [Modules/_ssl.o] Error 1
root@analog:/usr/src/Python-3.8.13# 
root@analog:/usr/src/Python-3.8.13# sudo make altinstall
gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall    -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration  -I./Include/internal  -I. -I./Include    -DPy_BUILD_CORE_BUILTIN  -DUSE_SSL -I/usr/include -I/usr/include/openssl -c ./Modules/_ssl.c -o Modules/_ssl.o
./Modules/_ssl.c:73:6: error: #error "libssl is too old and does not support X509_VERIFY_PARAM_set1_host()"
 #    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:909:9: error: implicit declaration of function 'SSL_get0_param' [-Werror=implicit-function-declaration]
         X509_VERIFY_PARAM *param = SSL_get0_param(self->ssl);
         ^
./Modules/_ssl.c:909:36: warning: initialization makes pointer from integer without a cast [enabled by default]
         X509_VERIFY_PARAM *param = SSL_get0_param(self->ssl);
                                    ^
./Modules/_ssl.c:911:13: error: implicit declaration of function 'X509_VERIFY_PARAM_set1_host' [-Werror=implicit-function-declaration]
             if (!X509_VERIFY_PARAM_set1_host(param, server_hostname,
             ^
./Modules/_ssl.c:917:13: error: implicit declaration of function 'X509_VERIFY_PARAM_set1_ip' [-Werror=implicit-function-declaration]
             if (!X509_VERIFY_PARAM_set1_ip(param, ASN1_STRING_get0_data(ip),
             ^
./Modules/_ssl.c: In function 'newPySSLSocket':
./Modules/_ssl.c:972:37: warning: initialization makes pointer from integer without a cast [enabled by default]
     X509_VERIFY_PARAM *ssl_params = SSL_get0_param(self->ssl);
                                     ^
./Modules/_ssl.c:973:5: error: implicit declaration of function 'X509_VERIFY_PARAM_set_hostflags' [-Werror=implicit-function-declaration]
     X509_VERIFY_PARAM_set_hostflags(ssl_params, sslctx->hostflags);
     ^
./Modules/_ssl.c: In function '_ssl__SSLContext_impl':
./Modules/_ssl.c:3174:23: error: 'X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS' undeclared (first use in this function)
     self->hostflags = X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS;
                       ^
./Modules/_ssl.c:3174:23: note: each undeclared identifier is reported only once for each function it appears in
./Modules/_ssl.c:3288:5: error: implicit declaration of function 'SSL_CTX_get0_param' [-Werror=implicit-function-declaration]
     params = SSL_CTX_get0_param(self->ctx);
     ^
./Modules/_ssl.c:3288:12: warning: assignment makes pointer from integer without a cast [enabled by default]
     params = SSL_CTX_get0_param(self->ctx);
            ^
./Modules/_ssl.c: In function 'get_verify_flags':
./Modules/_ssl.c:3603:11: warning: assignment makes pointer from integer without a cast [enabled by default]
     param = SSL_CTX_get0_param(self->ctx);
           ^
./Modules/_ssl.c: In function 'set_verify_flags':
./Modules/_ssl.c:3616:11: warning: assignment makes pointer from integer without a cast [enabled by default]
     param = SSL_CTX_get0_param(self->ctx);
           ^
./Modules/_ssl.c: In function 'set_host_flags':
./Modules/_ssl.c:3812:11: warning: assignment makes pointer from integer without a cast [enabled by default]
     param = SSL_CTX_get0_param(self->ctx);
           ^
cc1: some warnings being treated as errors
make: *** [Modules/_ssl.o] Error 1

Kindly need help.

This is beyond my pay grade. I think we need an SSL expert.

@tiran can you help here?

Your OS provides a very old, unsupported OpenSSL version. OpenSSL 1.0.1 has reached end of lifetime half a decade ago. You need at least OpenSSL 1.0.2, better 1.1.1.