sanjaysikdar.dev

Blog

HomeAboutTools
Sanjay Sikdar

Sanjay Sikdar

Software developer who enjoys developing software, solving challenges, and programming.

GithubLinkedInMain SiteSitemapRSS

© 2026 All rights reserved. Sanjay Sikdar

ubuntulinuxmysqldatabasedevops

Installing mysqlclient on Ubuntu 22.04 / 24.04

Sanjay Sikdar

Sanjay Sikdar

·May 6, 2024·2 min read

Error Like:

bash
Exception: Can not find valid pkg-config name.
Specify MYSQLCLIENT_CFLAGS and MYSQLCLIENT_LDFLAGS env vars manually
  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.

Solution:

bash
sudo apt install libmysqlclient-dev
# OR
sudo apt install libmariadb-dev-compat

You can use the mysql_config command to retrieve this information.

Now you need to Set the MYSQLCLIENT_CFLAGS and MYSQLCLIENT_LDFLAGS environment variable.

bash
mysql_config --cflags
 
# OUTPUT: -I/usr/include/mysql 
 
mysql_config --libs
 
# OUTPUT: -L/usr/lib/x86_64-linux-gnu -lmysqlclient -lz  -lzstd -lssl -lcrypto -lresolv -lm

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"

bash
export MYSQLCLIENT_CFLAGS="-I/usr/include/mysql"

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.

bash
export MYSQLCLIENT_LDFLAGS="-L/usr/lib/x86_64-linux-gnu -lmysqlclient -lz  -lzstd -lssl -lcrypto -lresolv -lm"

Now, when you install packages that require the MySQL client library.

bash
pip install mysqlclient

Reference: https://stackoverflow.com/questions/76875507/can-not-install-apache-airflow-providers-mysql-pkg-config-error

Additional:

bash
sudo apt-get install pkg-config build-essential
sudo bash -c "apt-get update && apt-get -y upgrade && apt-get -y autoremove && apt-get -y clean"
Sanjay Sikdar

Written by Sanjay Sikdar

Software developer who enjoys developing software, solving challenges, and programming.