0

when I'm running python3 manage.py runserver I get this message:

django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named 'MySQLdb'. 
Did you install mysqlclient or MySQL-python?

and because I'm using mysql database on python, I tried to install mysqlclient with pip3 I get another error:

Collecting mysqlclient
  Using cached mysqlclient-1.3.10.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/dd/vlr9cjt17_j4ccyzz89mld1w0000gn/T/pip-build-wt6g2_0e/mysqlclient/setup.py", line 17, in <module>
        metadata, options = get_config()
      File "/private/var/folders/dd/vlr9cjt17_j4ccyzz89mld1w0000gn/T/pip-build-wt6g2_0e/mysqlclient/setup_posix.py", line 54, in get_config
        libraries = [dequote(i[2:]) for i in libs if i.startswith('-l')]
      File "/private/var/folders/dd/vlr9cjt17_j4ccyzz89mld1w0000gn/T/pip-build-wt6g2_0e/mysqlclient/setup_posix.py", line 54, in <listcomp>
        libraries = [dequote(i[2:]) for i in libs if i.startswith('-l')]
      File "/private/var/folders/dd/vlr9cjt17_j4ccyzz89mld1w0000gn/T/pip-build-wt6g2_0e/mysqlclient/setup_posix.py", line 12, in dequote
        if s[0] in "\"'" and s[0] == s[-1]:
    IndexError: string index out of range  

       ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/dd/vlr9cjt17_j4ccyzz89mld1w0000gn/T/pip-build-wt6g2_0e/mysqlclient/

Also i read online that mysqlclient is not supported by python3 but i get a similar error when trying to instal MySQL-python:

 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/dd/vlr9cjt17_j4ccyzz89mld1w0000gn/T/pip-build-jp09s51k/MySQL-python/setup.py", line 13, in <module>
        from setup_posix import get_config
      File "/private/var/folders/dd/vlr9cjt17_j4ccyzz89mld1w0000gn/T/pip-build-jp09s51k/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/dd/vlr9cjt17_j4ccyzz89mld1w0000gn/T/pip-build-jp09s51k/MySQL-python/

How can I fix this and install mysql client for python or is there other method so I could use MySQL db in python?

Edit: python3 does support mysqlclient but not MySQL-python.

Sam Hartman
  • 6,210
  • 3
  • 23
  • 40
Mindutis
  • 43
  • 5
  • You are missing the Python MySQL "driver". There is an answer on how to install it here: http://stackoverflow.com/a/25865271/190823 – Jens Apr 26 '17 at 09:10
  • after running: 'brew install mysql-connector-c' i got msg that its already installed "Warning: mysql-connector-c-6.1.9 already installed" and running pip install MySQL-python throws same error. – Mindutis Apr 26 '17 at 09:14
  • *I read online that mysqlclient is not supported by python3 but I get the similar error when trying to install MySQL-python*. You have that the wrong way round. MySQL-python only supports Python 2. If you are using Python 3 you need mysqlclient. – Alasdair Apr 26 '17 at 09:15
  • Yeah, my bad on that one. Still getting same error on both – Mindutis Apr 26 '17 at 09:16

1 Answers1

0

I'm not sure what I did, but I think the problem for me was that I had a bad $PATH. I was trying to do one of the steps I found on Google and after resetting the bash_profile and setting the Python path again, it was fixed for me.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Mindutis
  • 43
  • 5