9

Following error recieved when running pip install 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/b_/xh05hxwd0lzc3rm858jsypdc0000gn/T/pip-build-AWDYaP/mysql-python/setup.py", line 17, in <module>
        metadata, options = get_config()
      File "setup_posix.py", line 53, in get_config
        libraries = [ dequote(i[2:]) for i in libs if i.startswith(compiler_flag("l")) ]
      File "setup_posix.py", line 8, 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/b_/xh05hxwd0lzc3rm858jsypdc0000gn/T/pip-build-AWDYaP/mysql-python/

I followed the instructions in this post around reinstalling setuptools and I have reinstalled Python from https://www.python.org/

which -a python gives

/Library/Frameworks/Python.framework/Versions/2.7/bin/python
/usr/local/bin/python
/usr/bin/python

The error seems to have occurred since installing MacOS 10.12.4 update

Community
  • 1
  • 1
Franco
  • 2,846
  • 7
  • 35
  • 54

7 Answers7

29

Solved with this

brew install mysql
pip install MySQL-python
Franco
  • 2,846
  • 7
  • 35
  • 54
  • 3
    Thanks for the solution. This was driving me nuts. Actually I had to do both yours and the other person: brew unlink mysql-connector-c and then brew install mysql – Stan Lin Jul 03 '17 at 00:04
  • Add a `brew link mysql` after that ^ – chadlagore Jun 20 '18 at 01:34
  • 2
    I made sure that mysql is installed and linked, and then run pip install MySQL-python and still same error – MhmdRizk Jul 04 '18 at 13:33
14

If you still failed with something like "Failed building wheel for mysql-python", try

LDFLAGS=-L/usr/local/opt/openssl/lib pip install mysql-python

which works like a charm for me.

Golden Thumb
  • 2,531
  • 21
  • 20
12

This worked for me (macOS Mojave 10.14.2):

brew install mysql@5.7
brew link --force mysql@5.7
brew install mysql-client
LDFLAGS=-L/usr/local/opt/openssl/lib pip install mysql-python
Ivan Kvas
  • 446
  • 6
  • 11
4

If you are like me and installed mysql from source in mac, then forget who are suggest to use brew - your machine already has mysql-connector-c. If you did brew install mysql-connector-c, do brew uninstall mysql-connector-c and try pip install mysql-python again (Python 3).

mold
  • 1,012
  • 7
  • 17
3

This worked for me:

    brew install mysql@5.7
    brew link --force mysql@5.7
1

To fix this we should edit mysql_config file.

For this, issue the command:

vi `which mysql_config`

This will open up the mysql_config in vi editor.

Press i to be in insert mode

Now find lines

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

for me it is on line 118. The above lines should be changed to

# Create options 
libs="-L$pkglibdir"
libs="$libs -lmysqlclient -lssl -lcrypto"

Now press esc button to exit from the insert mode and save the added content by issuing command:wq in vi editor.

Now try to reinstalling the MySQL-Python module using pip.

Note it is assumed that mysql and openssl are installed

padippist
  • 1,178
  • 1
  • 16
  • 30
1

For me this worked:

brew install mysql-connector-c 
pip install MySQL-python
pip install mysql-connector
David Webster
  • 2,208
  • 1
  • 16
  • 27