python setup.py egg_info mysqlclient

Den*_*sky 17 python macos mysql-python python-3.x macos-sierra

尝试在Python 3.6.0上使用pip3安装mysqlclient

$ pip3 install mysqlclient
Collecting mysqlclient
  Using cached mysqlclient-1.3.10.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/3k/08g3yx_12kg99kyfs989md600000gn/T/pip-build-1qv_89jc/mysqlclient/setup.py", line 17, in <module>
        metadata, options = get_config()
      File "/private/var/folders/3k/08g3yx_12kg99kyfs989md600000gn/T/pip-build-1qv_89jc/mysqlclient/setup_posix.py", line 54, in get_config
        libraries = [dequote(i[2:]) for i in libs if i.startswith('-l')]
      File "/private/var/folders/3k/08g3yx_12kg99kyfs989md600000gn/T/pip-build-1qv_89jc/mysqlclient/setup_posix.py", line 54, in <listcomp>
        libraries = [dequote(i[2:]) for i in libs if i.startswith('-l')]
      File "/private/var/folders/3k/08g3yx_12kg99kyfs989md600000gn/T/pip-build-1qv_89jc/mysqlclient/setup_posix.py", line 12, in dequote
        if s[0] in "\"'" and s[0] == s[-1]:
    IndexError: string index out of range

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/3k/08g3yx_12kg99kyfs989md600000gn/T/pip-build-1qv_89jc/mysqlclient/
Run Code Online (Sandbox Code Playgroud)

已经做了

brew install mysql-connector-c
Run Code Online (Sandbox Code Playgroud)

但仍然得到这个错误

kva*_*caj 48

这对我有用:

  1. brew install mysql-connector-c

  2. 编辑mysql_config(找到它:which mysql_config)

在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)
  1. brew info openssl
  2. 最后 pip3 install mysqlclient

  • 您应该更改权限或使用Vim编辑它并使用_wq!_来保存更改 (2认同)

yos*_*bel 8

我先解决了这个安装libmysqlclient-dev的问题:

sudo apt-get install libmysqlclient-dev
Run Code Online (Sandbox Code Playgroud)

希望对你有效.

  • OP提到“ OSX” (2认同)
  • @FranklinAntony对不起,它对我来说在Linux上修复了相同的错误,但对于Mac,它是:brew install mysql请参见以下链接:/sf/ask/130050301/ (2认同)

小智 5

经过大量的故障排除后,我发现它brew install mysql-connector-c只是不起作用.

问题源于系统无法识别mysql_config安装(这mysql-connector-c基本上是什么).Homebrew的方法(打开参数)安装mysql-connector-c在其中/Cellar/并创建一个符号链接到该/usr/local/bin/目录似乎导致问题,因为Python试图遵循符号链接.

为解决此问题,我执行了以下操作:

  1. brew uninstall mysql-connector-c
  2. 从Oracle的MySQL站点 下载/安装MacOS X MySQL Connector/C.
    • 注意:只需下载.dmg,这里不需要复杂......
  3. 重新启动MacOS终端(或iTerm2)以获得良好的衡量标准
  4. which mysql_config

    • 你应该看到正确的道路 /usr/local/bin/mysql/bin/mysql_config
  5. 激活virtualenv(如果适用)

  6. pip install mysqlclient

可能还有其他方法仍然使用Homebrew,但这是我找到的最直接的解决方案.

请注意,mysqlclientGitHub README.md还指出需要Python3的C-developer头文件.我认为那mysql-connector-c包括那些; 但是,如果您遇到更多问题,您也可以安装Xcode Developer CI Tools.

xcode-select --install

它们包括C编译器和Apple的其他开发人员实用程序.在这里阅读更多.