Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setup mysql with django on mac os

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.

like image 560
kamayani Avatar asked Jan 31 '26 21:01

kamayani


1 Answers

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.

like image 132
IJR Avatar answered Feb 03 '26 11:02

IJR



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!