【问题标题】:Cannot pip3 install mysqlclient无法 pip3 安装 mysqlclient
【发布时间】:2018-08-05 15:38:42
【问题描述】:

pip3 安装 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/58/m4f65nln59dbf0sf6x70l5zw0000gn/T/pip-build-ruton_ve/mysqlclient/setup.py", line 17, in <module>
        metadata, options = get_config()
      File "/private/var/folders/58/m4f65nln59dbf0sf6x70l5zw0000gn/T/pip-build-ruton_ve/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/58/m4f65nln59dbf0sf6x70l5zw0000gn/T/pip-build-ruton_ve/mysqlclient/setup_posix.py", line 54, in <listcomp>
        libraries = [dequote(i[2:]) for i in libs if i.startswith('-l')]
      File "/private/var/folders/58/m4f65nln59dbf0sf6x70l5zw0000gn/T/pip-build-ruton_ve/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/58/m4f65nln59dbf0sf6x70l5zw0000gn/T/pip-build-ruton_ve/mysqlclient/

关注了一些帖子并安装了

brew install mysql-connector-c

但仍然面临这个问题。

对于其他解决方案尝试以下解决方案,

https://stackoverflow.com/a/44338332/4107739

但找不到 /usr/local/bin/mysql/bin/mysql_config

我在 MacOS 上运行,对于 Mysql,我安装了 XAMPP。

【问题讨论】:

  • pip install --upgrade pip setuptools

标签: python-3.x macos pip mysql-python


【解决方案1】:

适用于 mac 上的 python3 + mysql。这对我有用:

  1. brew install mysql-connector-c
  2. 编辑 mysql_config(找到它:which mysql_config

在 mysql_config 中更改以下内容:

# 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

【讨论】:

    【解决方案2】:

    在 XAMPP 中,mysql_config 将位于以下路径中的某个位置。 (基于您的安装位置)

    /Applications/XAMPP/xamppfiles/bin/mysql_config
    

    更新 $PATH 以包含 bin 路径

    export PATH=$PATH:/Applications/XAMPP/xamppfiles/bin/
    

    运行mysql_config,--libs--libs_r应该有-lmysqlclient -lssl -lcrypto

     <XAMPP_PATH>mysql_config | grep libs
            --libs           [-L/usr/local/Cellar/mysql/5.7.21/lib -lmysqlclient -lssl -lcrypto]
            --libs_r         [-L/usr/local/Cellar/mysql/5.7.21/lib -lmysqlclient -lssl -lcrypto]
            --libmysqld-libs [-L/usr/local/Cellar/mysql/5.7.21/lib -lmysqld -lssl -lcrypto]
    

    如果没有,请将 mysql_config 更新为以下值。

    libs="-L$pkglibdir"
    libs="$libs -lmysqlclient -lssl -lcrypto"
    

    然后运行

    pip3 install mysqlclient
    

    【讨论】:

    • 我遇到了同样的问题,我在 ~/.bash_profile 中添加了export PATH=$PATH:/Applications/XAMPP/xamppfiles/bin/,然后运行pip3 install mysqlclient 它工作了
    猜你喜欢
    • 2017-06-14
    • 2020-03-20
    • 2017-07-27
    • 2018-07-05
    • 2018-12-26
    • 1970-01-01
    • 2018-03-14
    • 2021-07-05
    • 2018-06-10
    相关资源
    最近更新 更多