Nemo

Nemo 关注TA

路漫漫其修远兮,吾将上下而求索。

Nemo

Nemo

关注TA

路漫漫其修远兮,吾将上下而求索。

  •  普罗旺斯
  • 负责帅就完事了
  • 写了1,496,113字

该文章投稿至Nemo社区   Python  板块 复制链接


Mac 安装mysqlclient报错,OSError: mysql_config not found 的解决方法

发布于 2019/07/04 21:20 6,016浏览 0回复 3,229


使用pip3安装mysqlclient的时候,提示如下异常:

$ pip3 install mysqlclient

提示如下:

Collecting 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 "<string>", line 1, in <module>
File "/private/var/folders/fp/8rndwmss5nxdqwwkhsgxdpv40000gn/T/pip-install-h8mpixhz/mysqlclient/setup.py", line 16, in <module>
metadata, options = get_config()
File "/private/var/folders/fp/8rndwmss5nxdqwwkhsgxdpv40000gn/T/pip-install-h8mpixhz/mysqlclient/setup_posix.py", line 51, in get_config
libs = mysql_config("libs")
File "/private/var/folders/fp/8rndwmss5nxdqwwkhsgxdpv40000gn/T/pip-install-h8mpixhz/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/fp/8rndwmss5nxdqwwkhsgxdpv40000gn/T/pip-install-h8mpixhz/mysqlclient/


解决方法:

1、如果电脑没有安装brew,按照以下方式安装brew,再安装mysql-connector-c:

$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

2、安装mysql-connector-c:

$ brew install mysql-connector-c

3、重新安装:

$ pip3 install mysqlclient

然后还有如下异常:


Looking in indexes: http://pypi.douban.com/simple/
Collecting mysqlclient
Downloading http://pypi.doubanio.com/packages/f4/f1/3bb6f64ca7a429729413e6556b7ba5976df06019a5245a43d36032f1061e/mysqlclient-1.4.2.post1.tar.gz (85kB)
|████████████████████████████████| 92kB 2.3MB/s
ERROR: Complete output from command python setup.py egg_info:
ERROR: Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/fp/8rndwmss5nxdqwwkhsgxdpv40000gn/T/pip-install-ch66eofs/mysqlclient/setup.py", line 16, in <module>
metadata, options = get_config()
File "/private/var/folders/fp/8rndwmss5nxdqwwkhsgxdpv40000gn/T/pip-install-ch66eofs/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/fp/8rndwmss5nxdqwwkhsgxdpv40000gn/T/pip-install-ch66eofs/mysqlclient/setup_posix.py", line 53, in <listcomp>
libraries = [dequote(i[2:]) for i in libs if i.startswith('-l')]
File "/private/var/folders/fp/8rndwmss5nxdqwwkhsgxdpv40000gn/T/pip-install-ch66eofs/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/fp/8rndwmss5nxdqwwkhsgxdpv40000gn/T/pip-install-ch66eofs/mysqlclient/

4、编辑mysql_config配置文件:

$ vim  /usr/local/Cellar/mysql-connector-c/6.1.11/bin/mysql_config

找到:

libs="$libs -l "  

替换成:

libs="$libs -lmysqlclient -lssl -lcrypto"  

保存后再次尝试,即可正确安装。


本文标签
 {{tag}}
点了个评