Installing mariadb Python Connector on Ubuntu (Pop OS 22.04)

As I wanted to dabble with FastAPI, and a little weary of Windows for reasons which I shall not explore further, I decided to setup a virtual linux machine and run it full-screen. My computer is fast enough that I don’t notice any performance penalty by running windows first, and then virtualizing linux.

However, after spending a little more time than I would have liked googling or talking with AI chatbots about how to get all the software I wanted like python 3.13 and my preferred IDE installed from various sources, it was time to setup my python virtualenv and run a basic dev server. However the pip install command was failing with the following output:

$ pip install -r requirements.txt

Collecting fastapi<1.0.0,>=0.115.13 (from fastapi[standard]<1.0.0,>=0.115.13->-r requirements.txt (line 1))
  Using cached fastapi-0.116.1-py3-none-any.whl.metadata (28 kB)
Collecting mariadb<2.0.0,>=1.1.12 (from -r requirements.txt (line 2))
  Using cached mariadb-1.1.13.tar.gz (111 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
  ╰─> [38 lines of output]
      /bin/sh: 1: mariadb_config: not found
      Traceback (most recent call last):

My requirements.txt contained only two lines:

fastapi[standard] >= 0.115.13, < 1.0.0
mariadb >=1.1.12, <2.0.0

MariaDB connector cannot be installed for some reason. One of the many paper cuts that make using linux a bit more demanding than other OSes. Anyway, I vaguely recall the need to install development versions of certain packages when doing even python development on Linux.

The short of this is that you need to install the following packages which I found through trial and error after reading a few articles that weren’t very precise in what was needed:

python-dev
libmariadb-dev

For my use case, the database server is running on a different host, so no need to install mariadb-server.

If you’re using a python from the deadsnakes ppa, then you should install the corresponding python-dev package from there. For me, that was ‘python3.13-dev’. After this, the pip install for my two packages succeeded.