MAC安装mysqlclient失败,× Getting requirements to build wheel did not run successfully.│ exit code: 1╰─

在尝试使用pip安装mysqlclient时遇到了错误,主要是由于系统找不到mysql_config或mariadb_config命令。解决方案是通过Homebrew安装MySQL,然后重新运行pip安装命令。安装Homebrew后,使用brewinstallmysql,接着pipinstallmysqlclient,最终成功安装了mysqlclient。

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

问题:

在使用django项目安装mysqlclient时出现以下错误:

Collecting mysqlclient
  Using cached mysqlclient-2.1.1.tar.gz (88 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  error: subprocess-exited-with-error
  
  × Getting requirements to build wheel did not run successfully.
  │ exit code: 1
  ╰─> [27 lines of output]
      /bin/sh: mysql_config: command not found
      /bin/sh: mariadb_config: command not found
      /bin/sh: mysql_config: command not found
      mysql_config --version
      mariadb_config --version
      mysql_config --libs
      Traceback (most recent call last):
        File "/Users/ww/IT/PycharmProject/pyproject/lib/python3.8/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
          main()
        File "/Users/ww/IT/PycharmProject/pyproject/lib/python3.8/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
        File "/Users/ww/IT/PycharmProject/pyproject/lib/python3.8/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel
          return hook(config_settings)
        File "/private/var/folders/w6/3qy3y8294l9bv15sxd54n0mm0000gn/T/pip-build-env-w6vliiy5/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 341, in get_requires_for_build_wheel
          return self._get_build_requires(config_settings, requirements=['wheel'])
        File "/private/var/folders/w6/3qy3y8294l9bv15sxd54n0mm0000gn/T/pip-build-env-w6vliiy5/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 323, in _get_build_requires
          self.run_setup()
        File "/private/var/folders/w6/3qy3y8294l9bv15sxd54n0mm0000gn/T/pip-build-env-w6vliiy5/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 487, in run_setup
          super(_BuildMetaLegacyBackend,
        File "/private/var/folders/w6/3qy3y8294l9bv15sxd54n0mm0000gn/T/pip-build-env-w6vliiy5/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 338, in run_setup
          exec(code, locals())
        File "<string>", line 15, in <module>
        File "/private/var/folders/w6/3qy3y8294l9bv15sxd54n0mm0000gn/T/pip-install-9ai0k4t1/mysqlclient_68c540255d6b42808120a9e63553ac4d/setup_posix.py", line 70, in get_config
          libs = mysql_config("libs")
        File "/private/var/folders/w6/3qy3y8294l9bv15sxd54n0mm0000gn/T/pip-install-9ai0k4t1/mysqlclient_68c540255d6b42808120a9e63553ac4d/setup_posix.py", line 31, in mysql_config
          raise OSError("{} not found".format(_mysql_config_path))
      OSError: mysql_config not found
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.

解决方案:

1、先去登录brew官网:

macOS(或 Linux)缺失的软件包的管理器 — Homebrew

复制以下代码,到mac终端运行:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

安装好后根据提示运行一下两端代码:

1、代码:

(echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> /Users/ww/.zprofile

   

2、代码:

eval "$(/opt/homebrew/bin/brew shellenv)"

终端运行完后,确认brew已经安装完毕可以启动

brew help确认是否安装好

好了后,继续运行这两段代码:

$ brew install mysql
$ pip install mysqlclient

紧接着就是搞定

 

Successfully built mysqlclient
Installing collected packages: mysqlclient
Successfully installed mysqlclient-2.1.1

看到这个恭喜你! 

 

315.3 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 85.0/85.0 kB 5.7 MB/s eta 0:00:00 315.4 Collecting mysqlclient (from mysql->-r /app/requirements.txt (line 13)) 315.6 Downloading https://mirrors.aliyun.com/pypi/packages/61/68/810093cb579daae426794bbd9d88aa830fae296e85172d18cb0f0e5dd4bc/mysqlclient-2.2.7.tar.gz (91 kB) 315.6 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 91.4/91.4 kB 1.5 MB/s eta 0:00:00 315.7 Installing build dependencies: started 321.2 Installing build dependencies: finished with status 'done' 321.2 Getting requirements to build wheel: started 321.4 Getting requirements to build wheel: finished with status 'error' 321.4 error: subprocess-exited-with-error 321.4 321.4 × Getting requirements to build wheel did not run successfully. 321.4 exit code: 1 321.4 ╰─> [30 lines of output] 321.4 /bin/sh: 1: pkg-config: not found 321.4 /bin/sh: 1: pkg-config: not found 321.4 /bin/sh: 1: pkg-config: not found 321.4 /bin/sh: 1: pkg-config: not found 321.4 Trying pkg-config --exists mysqlclient 321.4 Command 'pkg-config --exists mysqlclient' returned non-zero exit status 127. 321.4 Trying pkg-config --exists mariadb 321.4 Command 'pkg-config --exists mariadb' returned non-zero exit status 127. 321.4 Trying pkg-config --exists libmariadb 321.4 Command 'pkg-config --exists libmariadb' returned non-zero exit status 127. 321.4 Trying pkg-config --exists perconaserverclient 321.4 Command 'pkg-config --exists perconaserverclient' returned non-zero exit status 127. 321.4 Traceback (most recent call last): 321.4 File "/usr/local/lib/python3.10/dist-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module> 321.4 main() 321.4 File "/usr/local/lib/python3.10/dist-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main 321.4 json_out['return_val'] = hook(**hook_input['kwargs']) 321.4 File "/usr/local/lib/python3.10/dist-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel 321.4 return hook(config_settings) 321.4 File "/tmp/pip-build-env-_t6_060o/overlay/local/lib/python3.10/dist-packages/setuptools/build_meta.py", line 334, in get_requires_for_build_wheel 321.4 return self._get_build_requires(config_settings, requirements=[]) 321.4 File "/tmp/pip-build-env-_t6_060o/overlay/local/lib/python3.10/dist-packages/setuptools/build_meta.py", line 304, in _get_build_requires 321.4 self.run_setup() 321.4 File "/tmp/pip-build-env-_t6_060o/overlay/local/lib/python3.10/dist-packages/setuptools/build_meta.py", line 320, in run_setup 321.4 exec(code, locals()) 321.4 File "<string>", line 156, in <module> 321.4 File "<string>", line 49, in get_config_posix 321.4 File "<string>", line 28, in find_package_name 321.4 Exception: Can not find valid pkg-config name. 321.4 Specify MYSQLCLIENT_CFLAGS and MYSQLCLIENT_LDFLAGS env vars manually 321.4 [end of output] 321.4 321.4 note: This error originates from a subprocess, and is likely not a problem with pip. 321.4 error: subprocess-exited-with-error 321.4 321.4 × Getting requirements to build wheel did not run successfully. 321.4exit code: 1 321.4 ╰─> See above for output. 321.4 321.4 note: This error originates from a subprocess, and is likely not a problem with pip. 322.0 322.0 [notice] A new release of pip is available: 24.0 -> 25.0.1 322.0 [notice] To update, run: python3.10 -m pip install --upgrade pip ------ failed to solve: process "/bin/sh -c pip install -i https://mirrors.aliyun.com/pypi/simple/ --no-cache-dir -r /app/requirements.txt" did not complete successfully: exit code: 1
最新发布
04-03
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

drunk_soul

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值