问题:linux centos 环境下,django项目安装mysqlclient报错:

(v_env) [pyapp: /home/userpy/workspace/v_env>pip install --upgrade mysqlclient --trusted-host mirrors.aliyun.com

Defaulting to user installation because normal site-packages is not writeable
Looking in indexes: http://mirrors.aliyun.com/pypi/simple
Collecting mysqlclient
Using cached http://mirrors.aliyun.com/pypi/packages/50/5f/eac919b88b9df39bbe4a855f136d58f80d191cfea34a3dcf96bf5d8ace0a/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 “/home/pyapp/.local/lib/python3.8/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py”, line 353, in
main()
File “/home/pyapp/.local/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 “/home/pyapp/.local/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 “/tmp/pip-build-env-j0x3q10s/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 “/tmp/pip-build-env-j0x3q10s/overlay/lib/python3.8/site-packages/setuptools/build_meta.py”, line 323, in _get_build_requires
self.run_setup()
File “/tmp/pip-build-env-j0x3q10s/overlay/lib/python3.8/site-packages/setuptools/build_meta.py”, line 487, in run_setup
super(_BuildMetaLegacyBackend,
File “/tmp/pip-build-env-j0x3q10s/overlay/lib/python3.8/site-packages/setuptools/build_meta.py”, line 338, in run_setup
exec(code, locals())
File “”, line 15, in
File “/tmp/pip-install-6m8hen1c/mysqlclient_d8b328b884704898962d255b91cc2dcf/setup_posix.py”, line 70, in get_config
libs = mysql_config(“libs”)
File “/tmp/pip-install-6m8hen1c/mysqlclient_d8b328b884704898962d255b91cc2dcf/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.

note: This error originates from a subprocess, and is likely not a problem with pip.

解决:

在尝试安装 mysqlclient 时遇到了问题。错误信息显示,安装过程中找不到 mysql_config 命令。这通常是因为您的系统中没有安装 MySQL 或 MariaDB 开发库。
在 CentOS 系统中,您可以通过以下命令安装这些库:

sudo yum install mysql-devel

如果您使用的是 MariaDB:

sudo yum install mariadb-devel

在安装了这些库之后,您应该就可以成功安装 mysqlclient 了。

06-08 17:18