zoukankan      html  css  js  c++  java
  • mac系统安装mysqlclient的一些坑(附解决方法)

    最近在学习Django,做ORM模型实验时候,我看老师用到数据库了,然后windows电脑就 pip install mysqlclient 安装就完事了。

    我的是mac,到我这就悲剧了,一个坑接着一个坑跳,我看网上有的人因为这个东西搞了一天的都有(手动“哭”)!

    直接上方法,不错,就是mysqlclient源码github目录直接有解决方法,操作标红的部分即可。

     --------------------------------------------------------

    Install

    Prerequisites

    You may need to install the Python and MySQL development headers and libraries like so:

    • sudo apt-get install python-dev libmysqlclient-dev # Debian / Ubuntu
    • sudo yum install python-devel mysql-devel # Red Hat / CentOS
    • brew install mysql-connector-c # macOS (Homebrew) (Currently, it has bug. See below)

    On Windows, there are binary wheels you can install without MySQLConnector/C or MSVC.

    Note on Python 3 : if you are using python3 then you need to install python3-dev using the following command :

    sudo apt-get install python3-dev # debian / Ubuntu

    sudo yum install python3-devel # Red Hat / CentOS

    Note about bug of MySQL Connector/C on macOS

    See also: https://bugs.mysql.com/bug.php?id=86971

    Versions of MySQL Connector/C may have incorrect default configuration options that cause compilation errors when mysqlclient-python is installed. (As of November 2017, this is known to be true for homebrew's mysql-connector-cand official package)

    Modification of mysql_config resolves these issues as follows.

    Change

    # on macOS, on or about line 112:
    # Create options 
    libs="-L$pkglibdir"
    libs="$libs -l "
    

    to

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

     --------------------------------------------------------

    解决方案:

     步骤一

    安装mysql-connector-c

    brew install mysql-connector-c

    步骤二

    修改mysql_config,这个文件在/usr/local/bin/mysql_config,实际在/usr/local/Cellar/mysql/8.0.23_1/bin/mysql_config

    直接修改

    # 记得sudo,不然没有权限,大概在文件120行左右(:set number 显示行号)
    
    sudo vi /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

    问题:

    还遇到一个坑,客户端就是下载不下来。不用想了,换个源吧,我换了中科大的源解决了

    解决方案:

    /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

    参考链接:

    https://my.oschina.net/u/914655/blog/1594267

    https://zhuanlan.zhihu.com/p/111014448

  • 相关阅读:
    面向对象设计的原则里氏代换原则
    阅读源码的一些错误观念
    gdb的一个bug Internal error: 【pc 0xxxxxxx】 in read in psymtab, but not in symtab
    STL中mem_fun和mem_fun_ref的用法
    每天写出好代码的5个建议
    /dev/null /dev/zero/
    SQL Server 2008 对 TSQL 语言的增强
    JQuery 应用JQuery.groupTable.js(二)
    jquery 实现iframe 自适应高度
    JQuery 应用JQuery.groupTable.js
  • 原文地址:https://www.cnblogs.com/soymilk2019/p/14778143.html
Copyright © 2011-2022 走看看