mac python pip安装mysqlclient报错

系统 1557 0

python mac安装mysqlclient报错

    • 如下解决办法
      • 解决办法

在python3中,django使用mysql时需要安装maysql驱动,django2.2中pymysql最高版本不够高,这里使用mysqlclient,但安装过程报错,这里记录一下。

            
              pip 
              
                install
              
               mysqlclient

            
          

但是报错

            
              Using cached https://files.pythonhosted.org/packages/f4/f1/3bb6f64ca7a429729413e6556b7ba5976df06019a5245a43d36032f1061e/mysqlclient-1.4.2.post1.tar.gz
    ERROR: Complete output from command python setup.py egg_info:
    ERROR: /bin/sh: mysql_config: command not found
    Traceback (most recent call last):
      File "
              
                ", line 1, in 
                
                  
      File "/private/var/folders/6c/jdnqnjsx48d8qj0kwn751c580000gn/T/pip-install-bz44wlso/mysqlclient/setup.py", line 16, in 
                  
                    
        metadata, options = get_config()
      File "/private/var/folders/6c/jdnqnjsx48d8qj0kwn751c580000gn/T/pip-install-bz44wlso/mysqlclient/setup_posix.py", line 51, in get_config
        libs = mysql_config("libs")
      File "/private/var/folders/6c/jdnqnjsx48d8qj0kwn751c580000gn/T/pip-install-bz44wlso/mysqlclient/setup_posix.py", line 29, in mysql_config
        raise EnvironmentError("%s not found" % (_mysql_config_path,))
    OSError: mysql_config not found
    ----------------------------------------
ERROR: Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/6c/jdnqnjsx48d8qj0kwn751c580000gn/T/pip-install-bz44wlso/mysqlclient/

                  
                
              
            
          

如下解决办法

安装mysql-connector-c

            
              brew install mysql-connector-c

            
          

成功之后再次安装

            
              pip install mysqlclient

            
          

出现另外错误:

            
              Using cached https://files.pythonhosted.org/packages/f4/f1/3bb6f64ca7a429729413e6556b7ba5976df06019a5245a43d36032f1061e/mysqlclient-1.4.2.post1.tar.gz
    ERROR: Complete output from command python setup.py egg_info:
    ERROR: Traceback (most recent call last):
      File "
              
                ", line 1, in 
                
                  
      File "/private/var/folders/6c/jdnqnjsx48d8qj0kwn751c580000gn/T/pip-install-i8sa5ttt/mysqlclient/setup.py", line 16, in 
                  
                    
        metadata, options = get_config()
      File "/private/var/folders/6c/jdnqnjsx48d8qj0kwn751c580000gn/T/pip-install-i8sa5ttt/mysqlclient/setup_posix.py", line 53, in get_config
        libraries = [dequote(i[2:]) for i in libs if i.startswith('-l')]
      File "/private/var/folders/6c/jdnqnjsx48d8qj0kwn751c580000gn/T/pip-install-i8sa5ttt/mysqlclient/setup_posix.py", line 53, in 
                    
                      
        libraries = [dequote(i[2:]) for i in libs if i.startswith('-l')]
      File "/private/var/folders/6c/jdnqnjsx48d8qj0kwn751c580000gn/T/pip-install-i8sa5ttt/mysqlclient/setup_posix.py", line 12, in dequote
        raise Exception("Wrong MySQL configuration: maybe https://bugs.mysql.com/bug.php?id=86971 ?")
    Exception: Wrong MySQL configuration: maybe https://bugs.mysql.com/bug.php?id=86971 ?
    ----------------------------------------
ERROR: Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/6c/jdnqnjsx48d8qj0kwn751c580000gn/T/pip-install-i8sa5ttt/mysqlclient/

                    
                  
                
              
            
          

解决办法

修改mysql_config文件,修改前先备份

            
              cp /usr/local/bin/mysql_config /usr/local/bin/mysql_config.backup

            
          

修改文件

            
              sudo vim /usr/local/bin/mysql_config 

            
          

找到如下内容

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

            
          

改为:

            
              # Create options 
libs="-L$pkglibdir"
libs="$libs -lmysqlclient -lssl -lcrypto"

            
          

再次执行

            
              pip install mysqlclient

            
          

安装成功!


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论