Python 3 ImportError: No module named 'ConfigParser'


I am trying to pip install the MySQL-python package, but I get an ImportError.

Jans-MacBook-Pro:~ jan$ /Library/Frameworks/Python.framework/Versions/3.3/bin/pip-3.3 install MySQL-python
Downloading/unpacking MySQL-python
  Running egg_info for package MySQL-python
    Traceback (most recent call last):
      File "<string>", line 16, in <module>
      File "/var/folders/lf/myf7bjr57_jg7_5c4014bh640000gn/T/pip-build/MySQL-python/", line 14, in <module>
        from setup_posix import get_config
      File "./", line 2, in <module>
        from ConfigParser import SafeConfigParser
    ImportError: No module named 'ConfigParser'
    Complete output from command python egg_info:
    Traceback (most recent call last):

  File "<string>", line 16, in <module>

  File "/var/folders/lf/myf7bjr57_jg7_5c4014bh640000gn/T/pip-build/MySQL-python/", line 14, in <module>

    from setup_posix import get_config

  File "./", line 2, in <module>

    from ConfigParser import SafeConfigParser

ImportError: No module named 'ConfigParser'

Command python egg_info failed with error code 1 in /var/folders/lf/myf7bjr57_jg7_5c4014bh640000gn/T/pip-build/MySQL-python
Storing complete log in /Users/jan/.pip/pip.log
Jans-MacBook-Pro:~ jan$ 

Any ideas?


In Python 3, ConfigParser has been renamed to configparser for PEP 8 compliance. It looks like the package you are installing does not support Python 3.

Answered By: Abe Karplus

You can instead use the mysqlclient package as a drop-in replacement for MySQL-python. It is a fork of MySQL-python with added support for Python 3.

I had luck with simply

pip install mysqlclient

in my python3.4 virtualenv after

sudo apt-get install python3-dev libmysqlclient-dev

which is obviously specific to ubuntu/debian, but I just wanted to share my success 🙂

Answered By: Eldamir

Here is a code that should work in both Python 2.x and 3.x

Obviously you will need the six module, but it’s almost impossible to write modules that work in both versions without six.

    import configparser
    from six.moves import configparser
Answered By: sorin

Kindly to see what is /usr/bin/python pointing to

if it is pointing to python3 or higher change to python2.7

This should solve the issue.

I was getting install error for all the python packages. Abe Karplus’s solution & discussion gave me the hint as to what could be the problem.
Then I recalled that I had manually changed the /usr/bin/python from python2.7 to /usr/bin/python3.5, which actually was causing the issue. Once I reverted the same. It got solved.

Answered By: AnotherDeveloper

This worked for me

cp /usr/local/lib/python3.5/ /usr/local/lib/python3.5/
Answered By: MaciejNg

If you are using CentOS, then you need to use

  1. yum install python34-devel.x86_64
  2. yum groupinstall -y 'development tools'
  3. pip3 install mysql-connector
  4. pip install mysqlclient
Answered By: Gaurav Nagpal

MySQL-python is not supported on python3 instead of this you can use mysqlclient

If you are on fedora/centos/Red Hat install following package

  1. yum install python3-devel
  2. pip install mysqlclient
Answered By: Kaushal

how about checking the version of Python you are using first.

import six
if six.PY2:
    import ConfigParser as configparser
    import configparser
Answered By: Gideon Kimutai

I run kali linux- Rolling and I came across this problem ,when I tried running in the terminal, after updating to python 3.6.0. After some research and trial I found that changing ConfigParser to configparser worked for me but then I came across another issue.

config = configparser.configparser()
AttributeError: module 'configparser' has no attribute 'configparser'

After a bit more research I realised that for python 3 ConfigParser is changed to configparser but note that it has an attribute ConfigParser().

Answered By: Oliver Wahome

Compatibility of Python 2/3 for configparser can be solved simply by six library

from six.moves import configparser
Answered By: Akif
pip install configparser
sudo cp /usr/lib/python3.6/ /usr/lib/python3.6/

Then try to install the mysql-python again.
That worked for me.

Answered By: Valere

Try this solution which worked fine for me.

Basically it’s to reinstall/upgrade to latest version of mysql from brew, and then installing mysqlclient or MySQL-Python from global pip3 instead of virtualenv pip3.

Then accessing the virtualenv and successfully install mysqlclient or MySQL-Python.

Answered By: Aishwary Dhare

I got further with Valeres answer:

pip install configparser
sudo cp /usr/lib/python3.6/ /usr/lib/python3.6/
Then try to install the MYSQL-python again. That Worked for me

I would suggest to link the file instead of copy it. It is save to update. I linked the file to /usr/lib/python3/ directory.

Answered By: ǝlpoodooɟƃuooʞ

I was having the same problem. Turns out, I needed to install python3 devel on my centos. First, you need to search for the package that is compatible with your system.

yum search python3 | grep devel

Then, install the package as:

yum install -y python3-devel.x86_64

Then, install mysqlclient from pip

pip install mysqlclient

Do pip3 install PyMySQL and then pip3 install mysqlclient.
Worked for me

Answered By: Roy Ash

I was getting the same error on Mac OS 10, Python 3.7.6 & Django 2.2.7. I want to use this opportunity to share what worked for me after trying out numerous solutions.


  1. Installed Connector/Python 8.0.20 for Mac OS from link

  2. Copy current dependencies into requirements.txt file, deactivated the current virtual env, and deleted it using;

    create the file if not already created with; touch requirements.txt

    copy dependency to file; python -m pip3 freeze > requirements.txt

    deactivate and delete current virtual env; deactivate && rm -rf <virtual-env-name>

  3. Created another virtual env and activated it using; python -m venv <virtual-env-name> && source <virtual-env-name>/bin/activate

  4. Install previous dependencies using; python -m pip3 install -r requirements.txt

Answered By: DKMDebugin

I still have this issue, so I go to /usr/lib/python3.8 and type as sudoer:


You may have another python version than 3.8.

Answered By: Bart Mensfort

For me the following command worked:

sudo python3 -m pip install mysql-connector
Answered By: Rene B.

Additional info:

Python 2x

import ConfigParser

Python 3x

import configparser
Answered By: Abhijit Manepatil

Following @MaciejNg I tried making a copy, which didn’t work:

sudo cp ./env/lib/python3.8/site-packages/ ./env/lib/python3.8/site-packages/

Because and are identical, I renamed the file:

sudo mv ./env/lib/python3.8/site-packages/ ./env/lib/python3.8/site-packages/
Answered By: Hrithik

base on your OS is centos use python3
if you don’t known where is or

  1. pip3 install configparser

  2. find / -name ""

  3. cd /usr/local/lib/python3.6/site-packages(base on your environment )

  4. cp

solved the issue

Answered By: morey
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.