简体   繁体   中英

'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!

Copy from this blog.

By finding out the information that mysql-connector-c might 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

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

This solved my issue:

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM