mac 安装 python mysqlclient 遇到的问题及解决方法

Posted yucaikang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mac 安装 python mysqlclient 遇到的问题及解决方法相关的知识,希望对你有一定的参考价值。

在 mac 上安装 mysqlclient 遇到了一些问题,查找资料很多人都遇到了同样的问题。通过资料和试验,成功了。这里记录一下,希望帮到遇到同样问题的人。

本人使用python3, 安装步骤如下:

brew install mysql-connector-c

pip3 install mysqlclient

当执行 pip3 install mysqlclient 是出现错误:

技术分享图片
? /usr/local/Cellar/mysql-connector-c/6.1.11/bin >pip3 install mysqlclient
Collecting mysqlclient
  Using cached mysqlclient-1.3.12.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/2w/56bgkvqd1xldl56fx_gx_fg00000gn/T/pip-build-f9admsgv/mysqlclient/setup.py", line 17, in <module>
        metadata, options = get_config()
      File "/private/var/folders/2w/56bgkvqd1xldl56fx_gx_fg00000gn/T/pip-build-f9admsgv/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/2w/56bgkvqd1xldl56fx_gx_fg00000gn/T/pip-build-f9admsgv/mysqlclient/setup_posix.py", line 54, in <listcomp>
        libraries = [dequote(i[2:]) for i in libs if i.startswith(‘-l‘)]
      File "/private/var/folders/2w/56bgkvqd1xldl56fx_gx_fg00000gn/T/pip-build-f9admsgv/mysqlclient/setup_posix.py", line 12, in dequote
        if s[0] in ""‘" and s[0] == s[-1]:
    IndexError: string index out of range

    ----------------------------------------
技术分享图片

解决方案:mysql_config                                                 (bin)

执行:vim mysql_config,搜索 libs,或者114行,替换为115行即可

112 # Create options
113 libs="-L$pkglibdir"
114 #libs="$libs -l "   ##源代码
115 libs="$libs -lmysqlclient -lssl -lcrypto "  ##修改成这样

再次执行pip3 install mysqlclient,成功了。如下所示:

技术分享图片
? /usr/local/Cellar/mysql-connector-c/6.1.11/bin >pip3 install mysqlclient
Collecting mysqlclient
  Using cached mysqlclient-1.3.12.tar.gz
Building wheels for collected packages: mysqlclient
  Running setup.py bdist_wheel for mysqlclient ... done
  Stored in directory: /Users/kk/Library/Caches/pip/wheels/df/bb/60/bf7c315cbe163515db1c846e4ffa5557dd785c82e82f3492e8
Successfully built mysqlclient
Installing collected packages: mysqlclient
Successfully installed mysqlclient-1.3.12
技术分享图片

 

以上是关于mac 安装 python mysqlclient 遇到的问题及解决方法的主要内容,如果未能解决你的问题,请参考以下文章

mac 安装 python mysqlclient 遇到的问题及解决方法

mac 安装 python mysqlclient 遇到的问题及解决方法

mac设置python及pip环境变量及安装mysqlclient

在 Mac OS X Sierra 上为 Django Python 安装 mysqlclient

Mac安装mysqlclient

mac下python3.6安装mysqlclient报错mysql_config: command