Defaulting to user installation because normal site-packages is not writeable
Collecting mysqlclient
Using cached mysqlclient-2.2.0.tar.gz (89 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
╰─> [25 lines of output]
Trying pkg-config --exists mysqlclient
Command 'pkg-config --exists mysqlclient' returned non-zero exit status 1.
Trying pkg-config --exists mariadb
Command 'pkg-config --exists mariadb' returned non-zero exit status 1.
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/pip/_vendor/pep517/in_process/_in_process.py", line 363, in
main()
File "/usr/lib/python3/dist-packages/pip/_vendor/pep517/in_process/_in_process.py", line 345, in main
json_out['return_val'] = hook(**hook_input['kwargs'])
File "/usr/lib/python3/dist-packages/pip/_vendor/pep517/in_process/_in_process.py", line 130, in get_requires_for_build_wheel
return hook(config_settings)
File "/usr/lib/python3/dist-packages/setuptools/build_meta.py", line 162, in get_requires_for_build_wheel
return self._get_build_requires(
File "/usr/lib/python3/dist-packages/setuptools/build_meta.py", line 143, in _get_build_requires
self.run_setup()
File "/usr/lib/python3/dist-packages/setuptools/build_meta.py", line 158, in run_setup
exec(compile(code, __file__, 'exec'), locals())
File "setup.py", line 154, in
ext_options = get_config_posix(get_options())
File "setup.py", line 48, in get_config_posix
pkg_name = find_package_name()
File "setup.py", line 27, in find_package_name
raise Exception(
Exception: Can not find valid pkg-config name.
Specify MYSQLCLIENT_CFLAGS and MYSQLCLIENT_LDFLAGS env vars manually
[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.
这个错误是我在使用pip安装mysqlclient时报错,意思是无法通过pkg-config找到MySQL客户端库,可能因为因为我没有设置mysql的环境变量MYSQLCLIENT_CFLAGS和 MYSQLCLIENT_LDFLAGS。所以需要手动指定MySQL的头文件和库路径:
前提因为我的已经安装了mysql数据库,我的mysql路径为usr/local/mysql
yum install mysql-devel

cp /usr/local/mysql/bin/pkgconfig/mysqlclient.pc /usr/lib64/pkgconfig/
vim /etc/profile
在文件末补充添加以下行:
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/lib64/pkgconfig
source /etc/profile
现在可以通过运行以下命令来验证是否添加成功:
echo $PKG_CONFIG_PATH
我是这样弄得,或许可以直接将msql/bin中的pkgconfig文件夹路径设置为环境变量
pip install mysqlclient
