Mac 安装 mysqlclient

前言

django里mysql backend用的mysqlclient,因此使用的话须要安装,但安装比较坑比php

错误过程-若是本身遇到了建议看下

觉得就是一条命令的事python

pip install mysqlclient

但连续不断的错误坑了有近2个小时mysql

1. 首先遇到的是git

EnvironmentError: mysql_config not foundgithub

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

2. 因而 数据库

brew install mysql-connector-cdjango

3. 再次 pip install mysqlclientbash

$ 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

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

 

正确过程

因而到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了

相关文章
相关标签/搜索