17

I'm on OSX El Capitan, using Python 2.7 (Anaconda). Launching the command pip install MySQL-python yields:

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/d2/gd004m2s35z5dlyz9mfn6sc40000gn/T/pip-build-FYvb_T/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

None of these worked (exit with same error).

  • pip install mysqlclient
  • easy_install MySQL-python

pip is up-to-date. I've basically tried to follow all suggestions in related questions, but none succeeded. Any help is appreciated, thanks!

mommi84
  • 614
  • 1
  • 9
  • 17

4 Answers4

36

Copy from this blog.

By finding out the information that mysql-connector-cmight come to the conclusion that the configuration by brew installation may be incorrect , open the /usr/local/bin/mysql_config script to modify some of the contents of it:

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

change into:

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

Save
Then re-install mysql-python:

pip install mysql-python
Rockie Yang
  • 4,725
  • 31
  • 34
wangpeng
  • 376
  • 2
  • 3
  • You might also need to run `export LDFLAGS="-L/usr/local/opt/openssl/lib"` and `export CPPFLAGS="-I/usr/local/opt/openssl/include"` before installing `mysql-python`. See the output of `brew info openssl` – Railslide Jun 02 '17 at 14:16
7

I met same error and solved with following instructions:

  1. brew uninstall mysql-connector-c
  2. brew install mysql
  3. invoke "mysql_config --libs" and confirm its output include correct library options: "-L/usr/local/Cellar/mysql/5.7.20/lib -lmysqlclient -lssl -lcrypto"
  4. export LDFLAGS=-L/usr/local/opt/openssl/lib && pip install mysqlclient
Yoichi Nakayama
  • 704
  • 6
  • 9
5

This solved my issue:

     brew install mysql@5.7
     brew link --force mysql@5.7
  • 2
    Yes, after installed this version. We also have to follow command `LDFLAGS=-L/usr/local/opt/openssl/lib pip install mysql-python`. I successfully installed in macOS 10.13.6. – anhtran May 06 '19 at 11:00
1

I got the same error while installing pip install MySql-python.

Then, I had installed libmysqlclient-dev using the command:

sudo apt install libmysqlclient-dev

After installing it, I tried again and pip install MySql-python and it worked for me.

Ahmed Ginani
  • 6,522
  • 2
  • 15
  • 33
  • Do you know where I can find the correspondent library for OSX? `brew install mysql` did not change anything, unfortunately. – mommi84 Apr 21 '17 at 13:32