问题(mysqlclient依赖问题)

问题一 (OSError: mysql_config not found)

ERROR: Command errored out with exit status 1:
command: xxx/venv/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/6p/_zlkj9s510l53q7_7cpq0_br0000gn/T/pip-install-cmdtjn9e/mysqlclient/setup.py'"'"'; __file__='"'"'/private/var/folders/6p/_zlkj9s510l53q7_7cpq0_br0000gn/T/pip-install-cmdtjn9e/mysqlclient/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base pip-egg-info
cwd: /private/var/folders/6p/_zlkj9s510l53q7_7cpq0_br0000gn/T/pip-install-cmdtjn9e/mysqlclient/
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
mysql_config --version
mariadb_config --version
mysql_config --libs
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/6p/_zlkj9s510l53q7_7cpq0_br0000gn/T/pip-install-cmdtjn9e/mysqlclient/setup.py", line 15, in <module>
metadata, options = get_config()
File "/private/var/folders/6p/_zlkj9s510l53q7_7cpq0_br0000gn/T/pip-install-cmdtjn9e/mysqlclient/setup_posix.py", line 70, in get_config
libs = mysql_config("libs")
File "/private/var/folders/6p/_zlkj9s510l53q7_7cpq0_br0000gn/T/pip-install-cmdtjn9e/mysqlclient/setup_posix.py", line 31, in mysql_config
raise OSError("{} not found".format(_mysql_config_path))
OSError: mysql_config not found
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

提取

OSError: mysql_config not found

开发环境中 mysqlclient 依赖 mysql_config 找不到抛出异常

解决方式

官方[链接](MySQL 客户端 ·皮皮 (pypi.org)

  • 安装 mysql
  • 安装 mysql-client (推荐)

mac环境

安装mysql

# Assume you are activating Python 3 venv
$ brew install mysql
$ pip install mysqlclient

安装 mysql-client

# Assume you are activating Python 3 venv
$ brew install mysql-client
$ echo 'export PATH="/usr/local/opt/mysql-client/bin:$PATH"' >> ~/.bash_profile
$ export PATH="/usr/local/opt/mysql-client/bin:$PATH"
$ pip install mysqlclient

系统本身问题 (mac)

ERROR: Command errored out with exit status 1:
command: xxx/venv/bin/python3 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/6p/_zlkj9s510l53q7_7cpq0_br0000gn/T/pip-install-i99x2u0n/mysqlclient_bb7fc20afe5541f28c040433ce3679af/setup.py'"'"'; __file__='"'"'/private/var/folders/6p/_zlkj9s510l53q7_7cpq0_br0000gn/T/pip-install-i99x2u0n/mysqlclient_bb7fc20afe5541f28c040433ce3679af/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'"'"'))' install --record /private/var/folders/6p/_zlkj9s510l53q7_7cpq0_br0000gn/T/pip-record-roolrinw/install-record.txt --single-version-externally-managed --compile --install-headers /Users/kai/Desktop/workspace/Projects/rock-demo/wz_transformer_api/venv/include/site/python3.9/mysqlclient
cwd: /private/var/folders/6p/_zlkj9s510l53q7_7cpq0_br0000gn/T/pip-install-i99x2u0n/mysqlclient_bb7fc20afe5541f28c040433ce3679af/
Complete output (41 lines):
mysql_config --version
['8.0.31']
mysql_config --libs
['-L/usr/local/opt/mysql-client/lib', '-lmysqlclient', '-lz', '-L/usr/local/lib', '-lzstd', '-L/usr/local/opt/openssl@1.1/lib', '-lssl', '-lcrypto', '-lresolv']
mysql_config --cflags
['-I/usr/local/opt/mysql-client/include/mysql']
ext_options:
library_dirs: ['/usr/local/opt/mysql-client/lib', '/usr/local/lib', '/usr/local/opt/openssl@1.1/lib']
libraries: ['mysqlclient', 'resolv']
extra_compile_args: ['-std=c99']
extra_link_args: []
include_dirs: ['/usr/local/opt/mysql-client/include/mysql']
extra_objects: []
define_macros: [('version_info', "(2,1,1,'final',0)"), ('__version__', '2.1.1')]
running install
running build
running build_py
creating build
creating build/lib.macosx-10.9-x86_64-3.9
creating build/lib.macosx-10.9-x86_64-3.9/MySQLdb
copying MySQLdb/__init__.py -> build/lib.macosx-10.9-x86_64-3.9/MySQLdb
copying MySQLdb/_exceptions.py -> build/lib.macosx-10.9-x86_64-3.9/MySQLdb
copying MySQLdb/connections.py -> build/lib.macosx-10.9-x86_64-3.9/MySQLdb
copying MySQLdb/converters.py -> build/lib.macosx-10.9-x86_64-3.9/MySQLdb
copying MySQLdb/cursors.py -> build/lib.macosx-10.9-x86_64-3.9/MySQLdb
copying MySQLdb/release.py -> build/lib.macosx-10.9-x86_64-3.9/MySQLdb
copying MySQLdb/times.py -> build/lib.macosx-10.9-x86_64-3.9/MySQLdb
creating build/lib.macosx-10.9-x86_64-3.9/MySQLdb/constants
copying MySQLdb/constants/__init__.py -> build/lib.macosx-10.9-x86_64-3.9/MySQLdb/constants
copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.9-x86_64-3.9/MySQLdb/constants
copying MySQLdb/constants/CR.py -> build/lib.macosx-10.9-x86_64-3.9/MySQLdb/constants
copying MySQLdb/constants/ER.py -> build/lib.macosx-10.9-x86_64-3.9/MySQLdb/constants
copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.9-x86_64-3.9/MySQLdb/constants
copying MySQLdb/constants/FLAG.py -> build/lib.macosx-10.9-x86_64-3.9/MySQLdb/constants
running build_ext
building 'MySQLdb._mysql' extension
creating build/temp.macosx-10.9-x86_64-3.9
creating build/temp.macosx-10.9-x86_64-3.9/MySQLdb
gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -Dversion_info=(2,1,1,'final',0) -D__version__=2.1.1 -I/usr/local/opt/mysql-client/include/mysql -I/Users/kai/Desktop/workspace/Projects/rock-demo/wz_transformer_api/venv/include -I/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -c MySQLdb/_mysql.c -o build/temp.macosx-10.9-x86_64-3.9/MySQLdb/_mysql.o -std=c99
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
error: command '/usr/bin/gcc' failed with exit code 1
----------------------------------------
ERROR: Command errored out with exit status 1: xxx/venv/include/site/python3.9/mysqlclient Check the logs for full command output.

提取

xcrun: error: invalid active developer path 

rror: command '/usr/bin/gcc' failed with exit code 1

可能是Xcode command line tools 丢失导致,每次升级 macOS 都会出现这个问题

xcode-select --install

过程很慢... 不建议升级 mac 系统

开发mac升级最新系统可能会遇到

  • 系统本身BUG-小白鼠性质
  • 安装软件时依赖不兼容