ModuleNotFoundError: No module named 'ConfigParser' - Python

avatar
Borislav Hadzhiev

Last updated: Apr 10, 2024
2 min

banner

# ModuleNotFoundError: No module named 'ConfigParser' - Python

The "ModuleNotFoundError: No module named 'ConfigParser'" occurs because the MySQL-python package does not support Python 3.

To solve the error, install the mysqlclient by running pip install mysqlclient.

modulenotfounderror no module named configparser

The mysqlclient module is a drop-in replacement for MySQL-python and supports Python 3.

Open your terminal in your project's root directory and install the module with the following command.

shell
# ๐Ÿ‘‡๏ธ In a virtual environment pip install mysqlclient # ๐Ÿ‘‡๏ธ For Python 3 (could also be pip3.10 depending on your version) pip3 install mysqlclient

pip install mysqlclient

If pip is not set up in your PATH environment variable, you might have to try one of the python -m pip commands.

shell
# ๐Ÿ‘‡๏ธ If you don't have pip in your PATH environment variable python -m pip install mysqlclient # ๐Ÿ‘‡๏ธ For Python 3 (could also be pip3.10 depending on your version) python3 -m pip install mysqlclient # ๐Ÿ‘‡๏ธ Using py alias (Windows) py -m pip install mysqlclient

using python m pip to install mysqlclient

If you get a permissions error, try running the command with the --user option or prefix it with sudo on macOS and Linux.

shell
# ๐Ÿ‘‡๏ธ If you get a permissions error pip install mysqlclient --user pip3 install mysqlclient --user # ๐Ÿ‘‡๏ธ On macOS or Linux sudo pip install mysqlclient sudo pip3 install mysqlclient

If the error persists, try to install the mysqlclient package with an operating system-specific command.

shell
# ๐Ÿ‘‡๏ธ For macOS brew install mysql pip install mysqlclient # ๐Ÿ‘‡๏ธ For Debian/Ubuntu sudo apt-get install python3-dev default-libmysqlclient-dev build-essential pip install mysqlclient # ๐Ÿ‘‡๏ธ For RedHat/CentOS sudo yum install python3-devel mysql-devel pip install mysqlclient

If you use Anaconda, use the following command to install mysqlclient.

shell
# ๐Ÿ‘‡๏ธ For Anaconda conda install -c conda-forge mysqlclient
shell
# ๐Ÿ‘‡๏ธ For Jupyter Notebook !pip install mysqlclient

The mysqlclient module is a fork of the unmaintained MySQL-python package and adds support for Python 3.

# Importing the configparser module from six.moves

If the error persists, try to import the configparser module from six.moves.

First, make sure you have the six module installed by running the following command.

shell
pip install six # ๐Ÿ‘‡๏ธ Or with pip3 pip3 install six

Now you can import the configparser module from the six.moves module.

main.py
from six.moves import configparser print(configparser)

# Alternatively, you can use the built-in configparser

Alternatively, you can use the built-in configparser module.

The module provides the ConfigParser class.

Here is an example from the docs.

main.py
import configparser sample_config = """ [mysqld] user = mysql pid-file = /var/run/mysqld/mysqld.pid skip-external-locking old_passwords = 1 skip-bdb # we don't need ACID today skip-innodb """ config = configparser.ConfigParser(allow_no_value=True) config.read_string(sample_config) print(config["mysqld"]["user"]) # ๐Ÿ‘‰๏ธ mysql print(config["mysqld"]["skip-bdb"]) # ๐Ÿ‘‰๏ธ None

The ConfigParser class implements a basic configuration language that provides a structure similar to that in Windows INI files.

ConfigParser classes are basically used to read and write INI files.

The official docs page has many examples of the supported INI file structure.

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.

Copyright ยฉ 2024 Borislav Hadzhiev