python setup.py egg_info mysqlclien

2024-04-26 13:14:16 发布

您现在位置:Python中文网/ 问答频道 /正文

尝试在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/

已经有了

brew install mysql-connector-c

但还是犯了这个错误


Tags: pipinpybuildifvarsetupline
3条回答

在进行了大量的故障排除之后,我发现brew install mysql-connector-c根本不起作用。

问题源于系统无法识别已安装的mysql_config(这就是mysql-connector-c的本质)。当Python试图遵循符号链接时,Homebrew在其/Cellar/中安装mysql-connector-c并创建指向/usr/local/bin/目录的符号链接的方法(open for argument)似乎导致了问题。

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

  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

可能还有其他方法可以继续使用自制,但这是我找到的最直接的解决方案。

注意,mysqlclientGitHub README.md还声明需要Python3的C-developer头。我假设mysql-connector-c包含这些;但是,如果遇到更多问题,您也可以安装Xcode开发人员CI工具,以获得良好的效果。

xcode-select --install

它们包括C编译器和其他来自苹果的开发工具。阅读更多here

我解决了首先安装libmysqlclient dev的问题:

sudo apt-get install libmysqlclient-dev

希望对你有用。

这对我有效:

  1. brew install mysql-connector-c

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

在mysql配置中更正此错误:

# Create options 
libs="-L$pkglibdir"
libs="$libs -l "

应该是:

# Create options 
libs="-L$pkglibdir"
libs="$libs -lmysqlclient -lssl -lcrypto"
  1. brew info openssl
  2. 最后pip3 install mysqlclient

相关问题 更多 >