Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'pip install MySQL-python' fails with 'IndexError'

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!

like image 597
mommi84 Avatar asked Apr 21 '17 13:04

mommi84


2 Answers

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
like image 76
wangpeng Avatar answered Oct 12 '22 19:10

wangpeng


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
like image 7
Yoichi Nakayama Avatar answered Oct 12 '22 21:10

Yoichi Nakayama