3

I am trying to setup mysql server with my django application but I am having trouble installing it correctly.

I used brew install mysql to install mysql server.

Then I used pip install mysqlclient which gives this 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/r9/n0ld0jk57x590rzq5kv8x4wc0000gn/T/pip-build-ZZb7dn/mysqlclient/setup.py", line 17, in <module>
        metadata, options = get_config()
      File "setup_posix.py", line 54, in get_config
        libraries = [dequote(i[2:]) for i in libs if i.startswith('-l')]
      File "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/r9/n0ld0jk57x590rzq5kv8x4wc0000gn/T/pip-build-ZZb7dn/mysqlclient/

Also tried, pip install MySQL-python but it also gives the same error message.

Am i doing something wrong here? Please guide me in the right direction, I recently shifted from linux to mac os and I am a little confused how things work here.

Note: I am trying to do this in a virtual environment.

kamayani
  • 253
  • 1
  • 3
  • 7
  • Try `pip search mysql | grep mysql` and search for your desired module to install within pip. Then `sudo pip install my_beloved_module`. – Chiheb Nexus Jun 04 '17 at 08:59
  • I don't think that's the full error. The actual cause of the error may have been right above the message you've given; do you know what it was? – numbermaniac Jun 04 '17 at 09:03
  • @ChihebNexus It is showing a number of packages that I think might work. I am not sure which one should I choose. They are too many. – kamayani Jun 04 '17 at 09:04
  • Did you try easy_install mysql-python ? – Kaushal Jun 04 '17 at 09:13
  • @Kaushal I did right now. It gives me an error saying "IndexError: string index out of range". – kamayani Jun 04 '17 at 09:15
  • That's strange, it looks like that's an error in mysqlclient's installation code. It looks like this might be worth reporting to the developers if you're not the only one: someone else seems to have had the error too: https://stackoverflow.com/q/43629713/3150837 – numbermaniac Jun 04 '17 at 23:20
  • 1
    @kamayani did you get any solution?? – nikdange_me Aug 27 '17 at 16:53

1 Answers1

4

For python3 + django 1.11 + mysql on mac. This worked for me:

  1. brew install mysql-connector-c
  2. edit mysql_config (locate it: which mysql_config)

Change the following in mysql_config:

# Create options #
libs="-L$pkglibdir"
libs="$libs -l "

To:

# Create options #
libs="-L$pkglibdir"
libs="$libs -lmysqlclient -lssl -lcrypto"
  1. brew info openssl

  2. and finally pip3 install mysqlclient

and done.

Prad
  • 150
  • 1
  • 4
  • 15
IJR
  • 1,288
  • 13
  • 14