错误案例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)
解决方案
- 在Mac 使用brew安装 mysql-connector-c
brew install mysql-connector-c
- 查找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
- 打开.bash_profile配置文件
vi ~/.bash_profile
- 将/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
- 使新配置的~/.bash_profile生效
(venv1) ➜ bin source ~/.bash_profile
- 测试是否成功
(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
版权声明:本文为qq_43370607原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。