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 "<string>", line 1, in <module>
File "/private/var/folders/vd/rc7lfsc90pv16rmt6m3fv62w0000gn/T/pip-install-l3xb37xq/mysqlclient/setup.py", line 16, in <module>
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安装成功。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 上周热点回顾(3.3-3.9)
· AI 智能体引爆开源社区「GitHub 热点速览」