报错的相关信息:
Collecting mysqlclient
Using cached mysqlclient-2.1.1.tar.gz (88 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/4l/9fx5h98x5z1fh9vy4h6phhy80000gn/T/pip-install-1y992754/mysqlclient_664ebe7b4953400db5829a6b8e4b4784/setup.py", line 15, in <module>
metadata, options = get_config()
File "/private/var/folders/4l/9fx5h98x5z1fh9vy4h6phhy80000gn/T/pip-install-1y992754/mysqlclient_664ebe7b4953400db5829a6b8e4b4784/setup_posix.py", line 70, in get_config
libs = mysql_config("libs")
File "/private/var/folders/4l/9fx5h98x5z1fh9vy4h6phhy80000gn/T/pip-install-1y992754/mysqlclient_664ebe7b4953400db5829a6b8e4b4784/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.
解决方案:
1、安装mysql-client
brew install mysql-client
2、给mysql-client配置环境
#通过以下命令找到mysql-client 的相关位置
locate mysql-client
#找到以下目录
/opt/homebrew/Cellar/mysql-client/8.0.30/bin
#打开.zshrc文件
open .zshrc
#配置环境变量,添加以下语句到zshrc文件下
export PATH="/opt/homebrew/Cellar/mysql-client/8.0.30/bin:$PATH"
3、安装myqlclient
pip install mysqlclient