mac mysql-config_Mac上安装mysqlclient报错:OSError: mysql_config not found

pip安装mysqlclient时报错如下

Collecting mysqlclient

Downloading http://mirrors.aliyun.com/pypi/packages/d0/97/7326248ac8d5049968bf4ec708a5d3d4806e412a42e74160d7f266a3e03a/mysqlclient-1.4.6.tar.gz (85 kB)

|████████████████████████████████| 85 kB 2.0 MB/s

ERROR: Command errored out with exit status 1:

command: /usr/local/opt/python@3.8/bin/python3.8 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/vd/rc7lfsc90pv16rmt6m3fv62w0000gn/T/pip-install-l3xb37xq/mysqlclient/setup.py'"'"'; __file__='"'"'/private/var/folders/vd/rc7lfsc90pv16rmt6m3fv62w0000gn/T/pip-install-l3xb37xq/mysqlclient/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/vd/rc7lfsc90pv16rmt6m3fv62w0000gn/T/pip-install-l3xb37xq/mysqlclient/pip-egg-info

cwd: /private/var/folders/vd/rc7lfsc90pv16rmt6m3fv62w0000gn/T/pip-install-l3xb37xq/mysqlclient/

Complete output (12 lines):

/bin/sh: mysql_config: command not found

/bin/sh: mariadb_config: command not found

/bin/sh: mysql_config: command not found

Traceback (most recent call last):

File "", line 1, in

File "/private/var/folders/vd/rc7lfsc90pv16rmt6m3fv62w0000gn/T/pip-install-l3xb37xq/mysqlclient/setup.py", line 16, in

metadata, options = get_config()

File "/private/var/folders/vd/rc7lfsc90pv16rmt6m3fv62w0000gn/T/pip-install-l3xb37xq/mysqlclient/setup_posix.py", line 61, in get_config

libs = mysql_config("libs")

File "/private/var/folders/vd/rc7lfsc90pv16rmt6m3fv62w0000gn/T/pip-install-l3xb37xq/mysqlclient/setup_posix.py", line 29, in mysql_config

raise EnvironmentError("%s not found" % (_mysql_config_path,))

OSError: mysql_config not found

解决方法如下:

安装 mysql-connector-c:

brew install mysql-connector-c

查找mysql_config的位置:

cd /usr/local/bin

find / -name mysql_config

输出:

/usr/local/bin/mysql_config

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

将/usr/local/Cellar/mysql-connector-c/6.1.11/bin/mysql_config配置到环境变量中:

vi ~/.bash_profile

配置:

PATH=/bin:/usr/bin:/usr/local/bin/:usr/local/Cellar/mysql-connector-c/6.1.11/bin/:${PATH}

export PATH

其中usr/local/Cellar/mysql-connector-c/6.1.11/bin/为新配置的环境变量。

使新配置的~/.bash_profile生效:

source ~/.bash_profile

备注:如果没有效果,需要在pycharm中的终端运行source ~/.bash_profile

最后,执行安装命令即可:

pip install mysqlclient==1.4.4

最后,mysqlclient安装成功。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值