当前位置: 首页 > ai >正文

Macos m系列芯片环境下python3安装mysqlclient系列问题

最近学习python3,在安装mysqlclient的时候遇到了一些问题,直接使用哦pip install mysqlclient 直接报错了,记录一下解决方案。

环境信息
设备:Macbook Pro m1
系统:macos Sequoia 15.3.2
最终成功的python版本:Python3.13.3
pip版本:25.0.1
最终系统环境下mysqlclient版本:2.2.7 -> 对应mysql-client: 8.0.42

直接执行命令安装: pip3 install mysqlclient,报错信息:

Collecting mysqlclientUsing cached mysqlclient-2.2.7.tar.gz (91 kB)Installing build dependencies ... doneGetting requirements to build wheel ... errorerror: subprocess-exited-with-error× Getting requirements to build wheel did not run successfully.│ exit code: 1╰─> [35 lines of output]/bin/sh: pkg-config: command not found/bin/sh: pkg-config: command not found/bin/sh: pkg-config: command not found/bin/sh: pkg-config: command not foundTrying pkg-config --exists mysqlclientCommand 'pkg-config --exists mysqlclient' returned non-zero exit status 127.Trying pkg-config --exists mariadbCommand 'pkg-config --exists mariadb' returned non-zero exit status 127.Trying pkg-config --exists libmariadbCommand 'pkg-config --exists libmariadb' returned non-zero exit status 127.Trying pkg-config --exists perconaserverclientCommand 'pkg-config --exists perconaserverclient' returned non-zero exit status 127.Traceback (most recent call last):File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 389, in <module>main()~~~~^^File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 373, in mainjson_out["return_val"] = hook(**hook_input["kwargs"])~~~~^^^^^^^^^^^^^^^^^^^^^^^^File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 143, in get_requires_for_build_wheelreturn hook(config_settings)File "/private/var/folders/pg/lcz_0brx7dl64hcxtkjtrn1c0000gp/T/pip-build-env-lqq7jo65/overlay/lib/python3.13/site-packages/setuptools/build_meta.py", line 331, in get_requires_for_build_wheelreturn self._get_build_requires(config_settings, requirements=[])~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File "/private/var/folders/pg/lcz_0brx7dl64hcxtkjtrn1c0000gp/T/pip-build-env-lqq7jo65/overlay/lib/python3.13/site-packages/setuptools/build_meta.py", line 301, in _get_build_requiresself.run_setup()~~~~~~~~~~~~~~^^File "/private/var/folders/pg/lcz_0brx7dl64hcxtkjtrn1c0000gp/T/pip-build-env-lqq7jo65/overlay/lib/python3.13/site-packages/setuptools/build_meta.py", line 317, in run_setupexec(code, locals())~~~~^^^^^^^^^^^^^^^^File "<string>", line 156, in <module>File "<string>", line 49, in get_config_posixFile "<string>", line 28, in find_package_nameException: Can not find valid pkg-config name.Specify MYSQLCLIENT_CFLAGS and MYSQLCLIENT_LDFLAGS env vars manually[end of output]note: This error originates from a subprocess, and is likely not a problem with pip.

看错误信息是少了pkg-config
执行命令:brew install pkg-config,也报错!!!

fatal: not in a git directory
Warning: No remote 'origin' in /opt/homebrew/Library/Taps/homebrew/homebrew-services, skipping update!
Running `brew update --auto-update`...
Warning: You are using macOS 15.
We do not provide support for this pre-release version.
It is expected behaviour that some formulae will fail to build in this pre-release version.
It is expected behaviour that Homebrew will be buggy and slow.
Do not create any issues about this on Homebrew's GitHub repositories.
Do not create any issues even if you think this message is unrelated.
Any opened issues will be immediately closed without response.
Do not ask for help from MacHomebrew on Twitter.
You may ask for help in Homebrew's discussions but are unlikely to receive a response.
Try to figure out the problem yourself and submit a fix as a pull request.
We will review it but may or may not accept it.==> Fetching pkg-config
==> Downloading https://pkgconfig.freedesktop.org/releases/pkg-config-0.29.2.tar
######################################################################## 100.0%
==> ./configure --prefix=/opt/homebrew/Cellar/pkg-config/0.29.2_3 --disable-host
==> make
Last 15 lines from /Users/nankexiansheng/Library/Logs/Homebrew/pkg-config/02.make:
gatomic.c:464:10: error: incompatible integer to pointer conversion passing 'gsize' (aka 'unsigned long') to parameter of type 'gpointer' (aka 'void *') [-Wint-conversion]464 |   return g_atomic_pointer_xor ((volatile gpointer *) atomic, val);|          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./gatomic.h:191:45: note: expanded from macro 'g_atomic_pointer_xor'191 |     (gsize) __sync_fetch_and_xor ((atomic), (val));                          \|                                             ^~~~~
4 errors generated.
make[6]: *** [libglib_2_0_la-gatomic.lo] Error 1
make[6]: *** Waiting for unfinished jobs....
make[5]: *** [all-recursive] Error 1
make[4]: *** [all] Error 2
make[3]: *** [all-recursive] Error 1
make[2]: *** [all] Error 2
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2Do not report this issue to Homebrew/brew or Homebrew/core!Error: You are using macOS 15.
We do not provide support for this pre-release version.
It is expected behaviour that some formulae will fail to build in this pre-release version.
It is expected behaviour that Homebrew will be buggy and slow.
Do not create any issues about this on Homebrew's GitHub repositories.
Do not create any issues even if you think this message is unrelated.
Any opened issues will be immediately closed without response.
Do not ask for help from MacHomebrew on Twitter.
You may ask for help in Homebrew's discussions but are unlikely to receive a response.
Try to figure out the problem yourself and submit a fix as a pull request.
We will review it but may or may not accept it.

解决方法:
mysqlclient安装
可以参考mysqlclient文档
首选确保你的macos已经安装配置好了brew,以及配置了国内源。

# 安装pkg-config
brew install pkg-config
注意:如果这里报错,先执行下brew install mysql;再执行brew install pkg-config命令
# 安装 mysql-client
brew install mysql-client@8.0
# 添加环境变量 在 ~/.zshrc 中添加下面这行
export PKG_CONFIG_PATH="$(brew --prefix)/opt/mysql-client@8.0/lib/pkgconfig"保存后 source ~/.zshrc 刷新环境变量通过 printenv 可以查看确认当前环境变量

接下来可以正常安装mysqlclient,这里我安装的是mysqlclient 2.2.7版本

注意⚠️:2.0.0 以上版本需要python3.8及以上才能兼容

pip3 install mysqlclient

如果正常安装完成,没有报错,进入当前python运行环境测试
在这里插入图片描述
如果能正常引入MySQLdb而没有报错,那么基本上算上顺利完成了。可以尝试在虚拟环境安装完依赖启动项目试试

http://www.xdnf.cn/news/2285.html

相关文章:

  • 数据需求管理办法有哪些?具体应如何应用?
  • 图神经网络(GNN)基本概念与核心原理
  • 某化工厂运维升级:智和信通运维平台实现工业交换机智能管理
  • Maven 4.0.0 模式-pom.xml配置详解
  • 《AI大模型应知应会100篇》第37篇:Agent框架入门:让AI具备自主行动能力
  • 数字巴别塔:全栈多模态开发框架如何用自然语言重构软件生产关系?
  • Unity 和 Unreal Engine(UE) 两大主流游戏引擎的核心使用方法
  • 回顾|Apache Cloudberry™ (Incubating) Meetup·2025 杭州站
  • MyBatis 类型处理器(TypeHandler)注册与映射机制:JsonListTypeHandler和JsonListTypeHandler注册时机
  • 174页Deepseek大模型在银行系统的部署方案
  • 一、I/O的相关概念
  • Spark RDD行动算子与共享变量实战:从数据聚合到分布式通信
  • 基于SpringBoot+PostgreSQL+ROS Java库机器人数据可视化管理系统
  • 热红外遥感在火情监测中有什么作用?
  • 深入Java JVM常见问题及解决方案
  • Java位运算符大全
  • 亚组风险比分析与可视化
  • OceanBase单机重启和配置修改
  • 再学GPIO(一)
  • 汽车制造行业如何在数字化转型中抓住机遇?
  • springboot不连接数据库启动(原先连接了mysql数据库)
  • 【Redis】Redis Zset实现原理:跳表+哈希表的精妙设计
  • C++初阶-STL简介
  • 怎样给MP3音频重命名?是时候管理下电脑中的音频文件名了
  • FlinkUpsertKafka深度解析
  • 重温TCP通信过程
  • C++ 类与对象(中)—— 默认成员函数与运算符重载的深度解析:构造函数,析构函数,拷贝构造函数,赋值运算符重载,普通取地址重载,const取地址重载
  • 【项目篇之垃圾回收】仿照RabbitMQ模拟实现消息队列
  • HTTP header Cookie 和 Set-Cookie
  • 系统架构师---基于规则的系统架构