mac python pip安装mysqlclient报错

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

安装成功!

你可能感兴趣的:(python)