'pip install MySQL-python'因'IndexError'而失败

mom*_*i84 16 python mysql pip mysql-python osx-elcapitan

我在OSX El Capitan上,使用Python 2.7(Anaconda).启动命令会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/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
Run Code Online (Sandbox Code Playgroud)

这些都不起作用(以相同的错误退出).

  • pip install mysqlclient
  • easy_install MySQL-python

pip已是最新.我基本上试图遵循相关问题中的所有建议,但都没有成功.任何帮助表示赞赏,谢谢!

小智 35

这个博客复制.

通过查找mysql-connector-c可能得出brew安装配置可能不正确的结论的信息,打开/usr/local/bin/mysql_config脚本以修改其中的一些内容:

#Create options
Libs = "-L$pkglibdir "
Libs = "$libs -l"
Run Code Online (Sandbox Code Playgroud)

变成:

#Create options
Libs = "-L$pkglibdir"
Libs = "$libs -lmysqlclient -lssl -lcrypto"
Run Code Online (Sandbox Code Playgroud)

保存
然后重新安装mysql-python:

pip install mysql-python
Run Code Online (Sandbox Code Playgroud)


小智 7

我遇到了同样的错误,并按照以下说明进行了解决:

  1. brew卸载mysql-connector-c
  2. brew安装mysql
  3. 调用“ mysql_config --libs”并确认其输出包括正确的库选项:“-L / usr / local / Cellar / mysql / 5.7.20 / lib -lmysqlclient -lssl -lcrypto”
  4. 导出LDFLAGS = -L / usr / local / opt / openssl / lib && pip install mysqlclient


小智 5

这解决了我的问题:

     brew install mysql@5.7
     brew link --force mysql@5.7
Run Code Online (Sandbox Code Playgroud)

  • 是的,安装此版本后。我们还必须遵循命令LDFLAGS = -L / usr / local / opt / openssl / lib pip install mysql-python。我已成功安装在macOS 10.13.6中。 (2认同)