mac mini M1 版本 pip installmysqlclient报错

在Mac M1芯片的系统中,尝试使用pip安装mysqlclient时遇到了因mysql_config命令未找到导致的错误。错误信息显示了mysql_config和mariadb_config两个命令都找不到。解决方案是通过brew安装mysql-connector-c,然后在.bash_profile中添加mysql_config的路径到环境变量,并执行source ~/.bash_profile使更改生效。经过这些步骤,成功安装了mysqlclient。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

mac mini M1 版本 pip installmysqlclient报错这里写自定义目录标题

错误案例1

(venvll) ➜  house-fill-backend git:(master) pip install mysqlclient
Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
Collecting mysqlclient
  Using cached https://mirrors.aliyun.com/pypi/packages/de/79/d02be3cb942afda6c99ca207858847572e38146eb73a7c4bfe3bdf154626/mysqlclient-2.1.0.tar.gz (87 kB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error
  
  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [16 lines of output]
      /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 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/private/var/folders/jp/5gv4t7ld6w357fdnhj7cztlr0000gn/T/pip-install-1fwix3k6/mysqlclient_0125d3d94747427e917b085d78d06e9d/setup.py", line 15, in <module>
          metadata, options = get_config()
        File "/private/var/folders/jp/5gv4t7ld6w357fdnhj7cztlr0000gn/T/pip-install-1fwix3k6/mysqlclient_0125d3d94747427e917b085d78d06e9d/setup_posix.py", line 70, in get_config
          libs = mysql_config("libs")
        File "/private/var/folders/jp/5gv4t7ld6w357fdnhj7cztlr0000gn/T/pip-install-1fwix3k6/mysqlclient_0125d3d94747427e917b085d78d06e9d/setup_posix.py", line 31, in mysql_config
          raise OSError("{} not found".format(_mysql_config_path))
      OSError: mysql_config not found
      mysql_config --version
      mariadb_config --version
      mysql_config --libs
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

错误案例2

(venvll) ➜  house-fill-backend git:(master) pip install mysqlclient
Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
Collecting mysqlclient
  Using cached https://mirrors.aliyun.com/pypi/packages/de/79/d02be3cb942afda6c99ca207858847572e38146eb73a7c4bfe3bdf154626/mysqlclient-2.1.0.tar.gz (87 kB)
    ERROR: Command errored out with exit status 1:
     command: /Users/lidong/Desktop/zhouyu/project/house-fill-backend/venvll/bin/python -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/jp/5gv4t7ld6w357fdnhj7cztlr0000gn/T/pip-install-_hrx0uvh/mysqlclient_12f10e02b7054febafb43cd00aa41760/setup.py'"'"'; __file__='"'"'/private/var/folders/jp/5gv4t7ld6w357fdnhj7cztlr0000gn/T/pip-install-_hrx0uvh/mysqlclient_12f10e02b7054febafb43cd00aa41760/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/jp/5gv4t7ld6w357fdnhj7cztlr0000gn/T/pip-pip-egg-info-ja99ae85
         cwd: /private/var/folders/jp/5gv4t7ld6w357fdnhj7cztlr0000gn/T/pip-install-_hrx0uvh/mysqlclient_12f10e02b7054febafb43cd00aa41760/
    Complete output (15 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/jp/5gv4t7ld6w357fdnhj7cztlr0000gn/T/pip-install-_hrx0uvh/mysqlclient_12f10e02b7054febafb43cd00aa41760/setup.py", line 15, in <module>
        metadata, options = get_config()
      File "/private/var/folders/jp/5gv4t7ld6w357fdnhj7cztlr0000gn/T/pip-install-_hrx0uvh/mysqlclient_12f10e02b7054febafb43cd00aa41760/setup_posix.py", line 70, in get_config
        libs = mysql_config("libs")
      File "/private/var/folders/jp/5gv4t7ld6w357fdnhj7cztlr0000gn/T/pip-install-_hrx0uvh/mysqlclient_12f10e02b7054febafb43cd00aa41760/setup_posix.py", line 31, in mysql_config
        raise OSError("{} not found".format(_mysql_config_path))
    OSError: mysql_config not found
    mysql_config --version
    mariadb_config --version
    mysql_config --libs
    ----------------------------------------
WARNING: Discarding https://mirrors.aliyun.com/pypi/packages/de/79/d02be3cb942afda6c99ca207858847572e38146eb73a7c4bfe3bdf154626/mysqlclient-2.1.0.tar.gz#sha256=973235686f1b720536d417bf0a0d39b4ab3d5086b2b6ad5e6752393428c02b12 (from https://mirrors.aliyun.com/pypi/simple/mysqlclient/) (requires-python:>=3.5). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
  Using cached https://mirrors.aliyun.com/pypi/packages/3c/df/59cd2fa5e48d0804d213bdcb1acb4d08c403b61c7ff7ed4dd4a6a2deb3f7/mysqlclient-2.0.3.tar.gz (88 kB)

解决方案

  1. 在Mac 使用brew安装 mysql-connector-c
brew install mysql-connector-c
  1. 查找mysql_config的位置
(venv1) ➜  bin find / -name mysql_config
find: /usr/sbin/authserver: Permission denied
/usr/local/mysql-8.0.27-macos11-arm64/bin/mysql_config
  1. 打开.bash_profile配置文件
vi ~/.bash_profile
  1. 将/usr/local/mysql-8.0.27-macos11-arm64/bin/mysql_config配置到环境变量中
 1 PATH=/bin:/usr/bin:/usr/local/bin/:/usr/local/mysql-8.0.27-macos11-arm64/bin/:${PATH}
 2 export PATH
  1. 使新配置的~/.bash_profile生效
(venv1) ➜  bin source ~/.bash_profile
  1. 测试是否成功
(venv1) ➜  bin pip install mysqlclient
Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
Collecting mysqlclient
  Using cached mysqlclient-2.1.0-cp39-cp39-macosx_10_9_universal2.whl
Installing collected packages: mysqlclient
Successfully installed mysqlclient-2.1.0
(venv1) ➜  bin pip list
Package     Version
----------- -------
mysqlclient 2.1.0
pip         22.0.4
setuptools  60.9.3
wheel       0.37.1
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值