1

Having moved to Python 3.11, I need to update Connector/Python - which requires the MariaDB Connector/C library.

This library is normally installed with

python -m pip install mariadb

But I'm getting an error:

MariaDB Connector/Python requires MariaDB Connector/C >= 3.3.1, found version 3.1.20

I can't see an ARM distribution for Connector/C on the mariadb pages, so I downloaded and build from source. All good.

  • How do I install the newly built library?
  • Or even remove the old version so the pip install will pick up the connect version?

mariadb server is '10.3.38-MariaDB-0+deb10u1 Raspbian 10', working fine. Just cannot connect to it from Python!

Rohit Gupta
  • 343
  • 2
  • 4
  • 11
tyddynonn
  • 19
  • 3

2 Answers2

1

I just went through all this on a new install of pi OS for a Computer Science class I teach - setting up to show the students how to make python scripts to read from a database via an apache2 server on a pi 4 - old school, no new frameworks.

From start to end, these are the commands I ran. (All were run with sudo).

From https://pimylifeup.com/raspberry-pi-mysql/

  1. apt install mariadb-server

  2. mysql_secure_installation (Follow the prompts to setup passwords)

Then, prepare for adding the mariadb package to python From https://mariadb.com/docs/server/connect/programming-languages/c/install/

  1. apt install libmariadb3 libmariadb-dev

Finally add mariadb to python

  1. python -m pip install mariadb --break-system-packages It warned me I shouldn't do this as root and should use a virtual env instead (https://pip.pypa.io/warnings/venv)

This all worked fine. The sample code I used for testing was to make a simple try.py script as follows (made sure the script was executable) and it worked without any trouble:

#!/usr/bin/python import mariadb conn = mariadb.connect( db='dbname', user='username', passwd='******', host='localhost') c = conn.cursor() c.execute("SELECT * FROM sometable") for row in c.fetchall(): print(row)

Specs: This is on pi OS 6.1.0-rpi7-rpi-v8 #1 SMP PREEMPT Debian 1:6.1.63-1+rpt1 (2023-11-24) aarch64, with Python 3.11.2, and mariadb 10.11.4-MariaDB-1~deb12u1 Debian 12

0

Very simple in the end - after building the Connector/C Library, I needed to

'sudo make install'

'python -m pip install mariadb' then ran fine.

Couple of wrinkles to watch out for:

  • You may need to make the Connector/C and MariaDb socket configurations line up. See https://stackoverflow.com/questions/57419743/change-socket-address-mariadb-config
  • The new Connector/C Libraries get built to the location specified in the cmake config. I then had to manually copy them to /usr/lib/arm-linux-gnueabihf which seems to be where the Python connector is looking for them. I'm sure there will be a better way to do this, but it worked for me.
tyddynonn
  • 19
  • 3