0

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.

Kampai
  • 22,848
  • 21
  • 95
  • 95
  • Possible duplicate of [Python 3 ImportError: No module named 'ConfigParser'](https://stackoverflow.com/questions/14087598/python-3-importerror-no-module-named-configparser) – Amit Yadav Oct 11 '19 at 04:26

2 Answers2

3

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

Amit Yadav
  • 4,422
  • 5
  • 34
  • 79
  • any idea how to fix this ? `cp: /usr/lib/python3.6/configparser.py: No such file or directory` ( MacOs X + python 3.6.5 ) – StyleZ Feb 11 '20 at 23:02
  • 1
    @StyleZ the second step I mentioned is to copy ConfigParser module configparser. This step is not required/recommended. You can simply use `configparser` in the code and it will work just fine. Just try `import configparser` and let me know if it works. – Amit Yadav Feb 12 '20 at 03:06
  • 1
    @StyleZ If you still wanna use the copy (`cp`) command to rename the package, you need to figure out where it is installed first. The location is `/usr/lib/python3.6` for me as I am using Ubuntu 18.04, it maybe different on MacOs X. A simple way to check the location of the *global* libraries is to use sys.path. 1. Open python shell by typing `python3.6` or `python3` 2. Run `import sys;print(sys.path)` 3. You will get multiple packages location, check which one has ConfigParser and run the `cp` command accordingly. Hope this helps! – Amit Yadav Feb 12 '20 at 06:56
  • 1
    thank you for your fast answer, I have acctually figured it out. I could not install the mysql-python package, because of this error, when I killed all processes and restarted the Mysql on my pc, it started working ( for some random reason ), so I got ti fixed. The thing is, you can not access the third party code, when its trying to get installled ( example: mysql-python ), so changing it would not work ( in my opinion ) + That searching for path and changing it there might work, but I dont need it anymore ( for now :D ). Thank you for your fast answer once again and have a niceday – StyleZ Feb 12 '20 at 14:30
0

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.

Mike Müller
  • 82,630
  • 20
  • 166
  • 161