ModuleNotFoundError: No module named 'mysql' in Python 3.10.0 (default, Nov 6 2021, 14:56:25) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux

Hi,

I have downloaded Python 3.10.0 on CentOS Linux release 7.9.2009 (Core). I have the below openssl and mariadb package installed on CentOS 7.9

# rpm -qa | grep openssl
openssl-libs-1.0.2k-22.el7_9.x86_64
openssl-devel-1.0.2k-22.el7_9.x86_64
openssl-1.0.2k-22.el7_9.x86_64

#rpm -qa | grep mariadb

mariadb-libs-5.5.68-1.el7.x86_64
mariadb-5.5.68-1.el7.x86_64
mariadb-server-5.5.68-1.el7.x86_64
mariadb-devel-5.5.68-1.el7.x86_64
#

#mysql -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.68-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> Bye
#


#wget https://www.python.org/ftp/python/3.10.0/Python-3.10.0.tgz

#tar xzf Python-3.10.0.tgz

#cd Python-3.10.0

#./configure --enable-optimizations

#make altinstall

# python3.10
Python 3.10.0 (default, Nov 6 2021, 14:56:25) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import mysql.connector
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'mysql'
>>>

#cat demo_mysql_test.py
import mysql.connector

# python3.10 demo_mysql_test.py
Traceback (most recent call last):
File "/root/demo_mysql_test.py", line 1, in <module>
import mysql.connector
ModuleNotFoundError: No module named 'mysql'
#
# pip3.10 install mysql-connector-python
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/mysql-connector-python/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/mysql-connector-python/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/mysql-connector-python/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/mysql-connector-python/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/mysql-connector-python/
Could not fetch URL https://pypi.org/simple/mysql-connector-python/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='[pypi.org](http://pypi.org/)', port=443): Max retries exceeded with url: /simple/mysql-connector-python/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
ERROR: Could not find a version that satisfies the requirement mysql-connector-python (from versions: none)
ERROR: No matching distribution found for mysql-connector-python
WARNING: You are using pip version 21.2.3; however, version 21.3.1 is available.
You should consider upgrading via the '/usr/local/bin/python3.10 -m pip install --upgrade pip' command.

Please guide me and let me know if I am missing anything. Thanks in advance and I look forward to hearing from you.

Best Regards,

Kaushal

Python 3.10 requires OpenSSL v1.1.1 or later:

See also the release notes.

Hi Erlend,

I have installed openssl11 package. I still face the same issue.

# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)

# whereis openssl
openssl: /usr/bin/openssl /usr/lib64/openssl /usr/include/openssl /usr/share/man/man1/openssl.1ssl.gz
# whereis openssl11
openssl11: /usr/bin/openssl11 /usr/lib64/openssl11 /usr/include/openssl11 /usr/share/man/man1/openssl11.1.gz

#

# rpm -qa | grep epel

epel-release-7-14.noarch
# rpm -qa | grep openssl
openssl11-1.1.1g-3.el7.x86_64
openssl-libs-1.0.2k-22.el7_9.x86_64
openssl-devel-1.0.2k-22.el7_9.x86_64
openssl11-libs-1.1.1g-3.el7.x86_64
openssl11-devel-1.1.1g-3.el7.x86_64
openssl-1.0.2k-22.el7_9.x86_64
#

#cd Python-3.10.0

# **./configure LDFLAGS="-L/usr/lib64/openssl11"**

#make altinstall
# pip3.10 install mysql-connector
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/mysql-connector/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/mysql-connector/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/mysql-connector/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/mysql-connector/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/mysql-connector/
Could not fetch URL https://pypi.org/simple/mysql-connector/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='[pypi.org](http://pypi.org/)', port=443): Max retries exceeded with url: /simple/mysql-connector/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
ERROR: Could not find a version that satisfies the requirement mysql-connector (from versions: none)
ERROR: No matching distribution found for mysql-connector
WARNING: You are using pip version 21.2.3; however, version 21.3.1 is available.
You should consider upgrading via the '/usr/local/bin/python3.10 -m pip install --upgrade pip' command.

# /usr/local/bin/python3.10 -m pip install --upgrade pip
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Requirement already satisfied: pip in /usr/local/lib/python3.10/site-packages (21.2.3)
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pip/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pip/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pip/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pip/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pip/
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='[pypi.org](http://pypi.org/)', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
WARNING: You are using pip version 21.2.3; however, version 21.3.1 is available.
You should consider upgrading via the '/usr/local/bin/python3.10 -m pip install --upgrade pip' command.
#

![](https://ssl.gstatic.com/ui/v1/icons/mail/images/cleardot.gif)

Thanks in advance and I look forward to hearing from you.

Best Regards,

Kaushal

The configure script has a couple of options for OpenSSL support:

$ ./configure --help | grep -i ssl
  --with-openssl=DIR      root of the OpenSSL directory
  --with-openssl-rpath=[DIR|auto|no]
                          Set runtime library directory (rpath) for OpenSSL
                          auto-detect rpath from --with-openssl and
  --with-ssl-default-suites=[python|openssl|STRING]
                          Python's preferred selection (default), openssl:
                          leave OpenSSL's defaults untouched, STRING: use a

The CentOS 7 openssl11 package is currently not supported. It places files in non-standard locations and uses the non-standard names for pkg-config modules (e.g. openssl11.pc).

Update

You could patch the configure script and force it to use openssl11 module:

sed -i 's/PKG_CONFIG openssl /PKG_CONFIG openssl11 /g' configure
yum install -y epel
yum install -y yum-utils make openssl11-devel
yum-builddep -y python3
1 Like