'pip install MySQL-python' fails with '

2019-01-23 06:16发布

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!

4条回答
We Are One
2楼-- · 2019-01-23 06:22

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.

查看更多
相关推荐>>
3楼-- · 2019-01-23 06:23

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
查看更多
三岁会撩人
4楼-- · 2019-01-23 06:41

This solved my issue:

     brew install mysql@5.7
     brew link --force mysql@5.7
查看更多
▲ chillily
5楼-- · 2019-01-23 06:42

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
查看更多
登录 后发表回答