I’m using Debian/Ubuntu, and I am trying to install an Airflow provider in my Python virtual environment:
$ pip install apache-airflow-providers-mysql
error: subprocess-exited-with-error
× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> [24 lines of output]
/bin/sh: 1: pkg-config: not found
/bin/sh: 1: pkg-config: not found
Trying pkg-config --exists mysqlclient
Command 'pkg-config --exists mysqlclient' returned non-zero exit status 127.
Trying pkg-config --exists mariadb
Command 'pkg-config --exists mariadb' returned non-zero exit status 127.
Traceback (most recent call last):
File "/home/user/airflow/airflow_env/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
main()
File "/home/user/airflow/airflow_env/lib/python3.10/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/user/airflow/airflow_env/lib/python3.10/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-a5nk1xf1/overlay/lib/python3.10/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-a5nk1xf1/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 323, in _get_build_requires
self.run_setup()
File "/tmp/pip-build-env-a5nk1xf1/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 338, in run_setup
exec(code, locals())
File "<string>", line 154, in <module>
File "<string>", line 48, in get_config_posix
File "<string>", line 27, in find_package_name
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.
I’m expecting to see the mysql provider in the airflow connection drop down.
3
Answers
specify the MYSQLCLIENT_CFLAGS and MYSQLCLIENT_LDFLAGS environment variables manually, follow the steps below:
Open a terminal window.
Determine the location of the MySQL header files and libraries. These locations may vary depending on your MySQL installation. You can use the
mysql_config
command to retrieve this information.Run the following command to find the location of the header files:
mysql_config --cflags
Run the following command to find the location of the libraries:mysql_config --libs
Note down the output of these commands, as you will need them in the next steps.Set the MYSQLCLIENT_CFLAGS environment variable. Replace “ with the path you obtained from the
mysql_config --cflags
command. Run the following command:export MYSQLCLIENT_CFLAGS="-I"
Set the MYSQLCLIENT_LDFLAGS environment variable. Replace “ with the path you obtained from the
mysql_config --libs
command.Run the following command:
export MYSQLCLIENT_LDFLAGS="-L"
Note: If your MySQL installation includes multiple libraries, separate each library path with a space.Now, when you install packages that require the MySQL client library, such as
mysqlclient
for Django, the build process will use the specified CFLAGS and LDFLAGS values to locate the necessary files. You can proceed with your package installation or Django setup, and the specified environment variables will be used to locate the MySQL client libraries.By manually setting the MYSQLCLIENT_CFLAGS and MYSQLCLIENT_LDFLAGS environment variables, you can ensure that the correct MySQL header files and libraries are used during the installation or compilation process.
I solved the same problem as you using this method
My pc is macbook,
can solve it
pkg-config: not found
is a major hint at the problem and the solution – you’re missing build tools and you need to install them.note: If you’re actually building on a Docker slim image, see: https://stackoverflow.com/a/77433206/1554386