• Mac安装MySQL-python报错解决


    Mac安装MySQL-pyhton报错

    今天在Mac上安装MySQL-python报错,搜遍网络都说什么mysql config路径问题,但是都不行。

    解决方案

    一开始遇到的问题是:

    Complete output from command python setup.py egg_info:
    sh: mysql_config: command not found
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/jy/7ybw8dpj71n9yhk_xj5jttxc0000gn/T/pip-install-NknW3b/MySQL-python/setup.py", line 17, in <module>
        metadata, options = get_config()
      File "setup_posix.py", line 43, in get_config
        libs = mysql_config("libs_r")
      File "setup_posix.py", line 25, in mysql_config
        raise EnvironmentError("%s not found" % (mysql_config.path,))
    EnvironmentError: mysql_config not found
    
    ----------------------------------------
    Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/jy/7ybw8dpj71n9yhk_xj5jttxc0000gn/T/pip-install-NknW3b/MySQL-python/
    

    找了一下发现是应为没有安装mysql-connector-c,安装brew install mysql-connector-c
    再次安装MySQL-python,发现还是报错,但是报错信息变了:

    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/jy/7ybw8dpj71n9yhk_xj5jttxc0000gn/T/pip-install-u39xuY/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
    
    ----------------------------------------
    Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/jy/7ybw8dpj71n9yhk_xj5jttxc0000gn/T/pip-install-u39xuY/MySQL-python/
    

    网上搜了一圈,但是解决方案都不对,最后发现是mysql-connector-c本身的配置问题,修改文件

    /usr/local/Cellar/mysql-connector-c/6.1.11/bin/mysql_config:

    cd /usr/local/Cellar/mysql-connector-c/6.1.11/bin/
    # 修改之前先备份,防止改坏了
    cp mysql_config mysql_config.bak
    # 修改文件
    sudo vim mysql_config
    
    # 将对应的内容修改为
    # Create options
    libs="-L$pkglibdir"
    # libs="$libs -l "
    libs="$libs -lmysqlclient -lssl -lcrypto "
    
    

    再次安装pip install MySQL-python, 成功

  • 相关阅读:
    Qt 的插件制作遇到的问题
    Qt实现原生Flow实现不了的Item错误排列效果,类似淘宝商品展示
    通过pro文件使Qt的build目录更清爽
    No rule to make target
    Qtcreator中printf()/fprintf()不显示问题处理方法
    QtCreator集成的MSVC套件有问题
    启动程序失败,路径或者权限错误
    图数据库 Nebula Graph 的数据模型和系统架构设计
    NLP(十六)轻松上手文本分类
    NLP(十五)让模型来告诉你文本中的时间
  • 原文地址:https://www.cnblogs.com/zzhaolei/p/11068039.html
Copyright © 2020-2023  润新知