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!

2
  • "Having moved to Python 3.11" HOW?? WHY?? If you choose to use an unsupported version you need to do everything from scratch. You aren't even using the appropriate commands for Buster; python2 is obsolete. If for some reason you think you need a different version you should use virtual environment.
    – Milliways
    Commented Mar 18, 2023 at 9:35
  • My python3 environment is working fine in all respects except this. I'm not sure why you think I'm using python2 - my 'python' command is aliased to python3.
    – tyddynonn
    Commented Mar 18, 2023 at 12:07

2 Answers 2

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.
0
0

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

1
  • steps 2 and 4 are confusing because they contain text that is not part of the command
    – jsotola
    Commented Feb 19 at 17:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.