0

I am trying to connect a MySQL database to my Django project, but when I try to install MySQL-python, it gives me the following error:

Collecting mysql-python
  Using cached MySQL-python-1.2.5.zip
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/fr/3k1nrq490dzdz9s48k49m9640000gn/T/pip-build-4dsuxwwv/mysql-python/setup.py", line 13, in <module>
        from setup_posix import get_config
      File "/private/var/folders/fr/3k1nrq490dzdz9s48k49m9640000gn/T/pip-build-4dsuxwwv/mysql-python/setup_posix.py", line 2, in <module>
        from ConfigParser import SafeConfigParser
    ModuleNotFoundError: No module named 'ConfigParser'

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/fr/3k1nrq490dzdz9s48k49m9640000gn/T/pip-build-4dsuxwwv/mysql-python/

I have tried pip3 install ConfigParser, but while it gets installed, the error still occurs.

When I try to run my Django server, it prints out a long error log, and at the end:

django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
Did you install mysqlclient?

and when I looked at the following link, it said that I should install MySQL-python: Django mysqlclient install

May seem like a newbie question, but I can't seem to find similar errors elsewhere online.

EDIT:: Ok, looks like MySQL-python is not for python-3.6

While I did pip3 install mysqlclient, the virtualenv is saying that I have already installed it when I run the command again. But when I try to python3 manage.py runserver, I get the above error, asking if I had installed it. When I try to give an answer, I am unable to. Everytime I press ENTER, it just creates a new line and the prompt is still active.

The above error is preceded by the following text:

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x1059d9048>
Traceback (most recent call last):
  File "/Users/karthikpullela/Desktop/Django-projects/QB-test/QB/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 15, in <module>
    import MySQLdb as Database
  File "/Users/karthikpullela/Desktop/Django-projects/QB-test/QB/lib/python3.6/site-packages/MySQLdb/__init__.py", line 19, in <module>
    import _mysql
ImportError: dlopen(/Users/karthikpullela/Desktop/Django-projects/QB-test/QB/lib/python3.6/site-packages/_mysql.cpython-36m-darwin.so, 2): Library not loaded: libmysqlclient.18.dylib
  Referenced from: /Users/karthikpullela/Desktop/Django-projects/QB-test/QB/lib/python3.6/site-packages/_mysql.cpython-36m-darwin.so
  Reason: image not found

The above exception was the direct cause of the following exception:
  • 1
    Possibly duplicated: https://stackoverflow.com/questions/14087598/python-3-importerror-no-module-named-configparser – dvnguyen Dec 28 '17 at 23:34
  • Possible duplicate of [Python 3 ImportError: No module named 'ConfigParser'](https://stackoverflow.com/questions/14087598/python-3-importerror-no-module-named-configparser) – meshy Dec 28 '17 at 23:35
  • Got it, thanks for the heads up. But, whenever I try to run python3 manage.py runserver, I get the following error, and when I try to answer, I am unable to: django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module. Did you install mysqlclient? – karthikpullela Dec 28 '17 at 23:39
  • That's the result of unsuccessfully installation of MySQL-python. Once you can install it, the later error message will disappear. – dvnguyen Dec 28 '17 at 23:44
  • What if you used the recommend driver instead? https://docs.djangoproject.com/en/2.0/ref/databases/#mysql-db-api-drivers –  Dec 28 '17 at 23:48
  • Here's the thing. According to the other stackoverflow link, MySQL-python does not work for python3, and I am using python3. Apparently I need mysqlclient, which, while I have it already installed, is not working. – karthikpullela Dec 28 '17 at 23:50
  • It's possible that you installed it into the wrong environment. –  Dec 28 '17 at 23:51
  • I checked and I have installed it into the correct environment: `(QB) Karthiks-MacBook-Pro:QuikBikes karthikpullela$ pip3 list DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning. configparser (3.5.0) Django (2.0) django-cors-headers (2.1.0) mysqlclient (1.3.12) pip (9.0.1) pytz (2017.3) setuptools (38.2.5) wheel (0.30.0)` – karthikpullela Dec 28 '17 at 23:55

2 Answers2

0

Python 3 does not include ConfigParser only has configparser

>>> import ConfigParser
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'ConfigParser'
>>> import configparser

Try Python 2.7 which still works if we use import ConfigParser

cacti5
  • 2,006
  • 2
  • 25
  • 33
has0511
  • 11
  • 2
0

Try to install with different package, it has support for python 3.

pip install mysqlclient

If there is error while installing in virtualenv, do install this first.

sudo apt-get -y install python3-dev libmysqlclient-dev
jahmed31
  • 3,456
  • 3
  • 23
  • 23