from ConfigParser import SafeConfigParser ImportError: No module named 'ConfigParser'

19.7k Views Asked by At

I am getting below error:

"from ConfigParser import SafeConfigParser ImportError: No module named 'ConfigParser''

I am trying to install Mysql-python in python3 but not getting success.

2

There are 2 best solutions below

0
On

In Python 2 this works:

from ConfigParser import SafeConfigParser 

Python is case sensitive and in Python 3 the module was renamed to configparser So you would need import like this:

from configparser import SafeConfigParser

Looks like the library you trying to install is for Python 2. You need to get the Python 3 version.

4
On

The package is renamed to configparser for PEP 8 compliance and the package you are trying to install doesn't support Python 3.

You can use mysqlclient instead. You can install it using the below command:

pip install mysqlclient

Or one more alternative is there which I won't personally recommend, but just to share it:

# Install configparser
pip install configparser

# Rename it to ConfigParser
sudo cp /usr/lib/python3.6/configparser.py /usr/lib/python3.6/ConfigParser.py

After doing the above, you should be able to download MySQL-python without problems.

P.S: Answer is inspired by the answers to this question