Mac 安装 mysqlclient

前言

django里mysql backend用的mysqlclient,所以使用的话需要安装,但安装比较坑比

错误过程-如果自己遇到了建议看下

以为就是一条命令的事

pip install mysqlclient

但接二连三的错误坑了有近2个小时

1. 首先遇到的是

EnvironmentError: mysql_config not found

网上查了下,大致意思是说需要安装mysql,不能把,就连一下数据库,还需要下一个数据库?又继续看了下,原来是要装一个mysql的开发包就可以了(当然你安装mysql也是可以的)

2. 于是 

brew install mysql-connector-c

3. 再次 pip install mysqlclient

$ pip 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/y5/rz5w2dqx00s24rgcgdzyf9z80000gn/T/pip-build-jckrqk4x/mysqlclient/setup.py", line 17, in <module>
        metadata, options = get_config()
      File "/private/var/folders/y5/rz5w2dqx00s24rgcgdzyf9z80000gn/T/pip-build-jckrqk4x/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/y5/rz5w2dqx00s24rgcgdzyf9z80000gn/T/pip-build-jckrqk4x/mysqlclient/setup_posix.py", line 54, in <listcomp>
        libraries = [dequote(i[2:]) for i in libs if i.startswith('-l')]
      File "/private/var/folders/y5/rz5w2dqx00s24rgcgdzyf9z80000gn/T/pip-build-jckrqk4x/mysqlclient/setup_posix.py", line 12, in dequote
        if s[0] in "\"'" and s[0] == s[-1]:
    IndexError: string index out of range

还是报错,不至于这么复杂吧

 

正确过程

于是到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_config时因为是只读的,需要chmod 777 设置下,改完后再改回来

修改完后 再次安装ok了

 

 

 

转载于:https://my.oschina.net/u/914655/blog/1594267

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值