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

问题:

在使用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 
          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 "", line 15, in 
        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

看到这个恭喜你! 

 

本文来自网络,不代表协通编程立场,如若转载,请注明出处:https://net2asp.com/1cd3df199c.html