[Python] Unable to pip install MariaDB in Python

Discussão em 'Python' iniciado por Stack, Fevereiro 28, 2025.

  1. Stack

    Stack Membro Participativo

    I've been reading all the other posts somewhat related to this topic but I appear to have a slice of knowledge missing to fully comprehend the full picture.

    Objective: I need to be able to access a MariaDB database on a remote server from my very simple app (local or in docker) so that I can run a couple of select scripts on the data.

    I've opted to use Docker because it's cleaner and less prone to interference from my local OS, but regardless, I get the same errors on both MacOS locally and Linux on Docker.

    This is my Dockerfile (the app works fine until I try to add MariaDB):

    FROM python:3.8

    WORKDIR /usr/src/app

    RUN apt-get update
    RUN apt-get install libmariadb3 libmariadb-dev

    COPY . .

    RUN pip install --upgrade pip
    RUN pip install --upgrade setuptools
    RUN pip install --no-cache-dir -r requirements.txt

    EXPOSE 5000

    CMD ["python", "./app.py"]


    This is my requirements.txt (I don't need Flask but I just want to make sure I can see that pip is able to install something correctly, and it does):

    Flask==2.0.2
    mariadb==1.1.4


    When I run a docker build, I get this:

    RUN pip install --no-cache-dir -r requirements.txt:
    #11 1.253 Collecting Flask==2.0.2
    #11 1.397 Downloading Flask-2.0.2-py3-none-any.whl (95 kB)
    #11 1.441 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 95.2/95.2 kB 4.7 MB/s eta 0:00:00
    #11 1.527 Collecting mariadb==1.1.4
    #11 1.558 Downloading mariadb-1.1.4.zip (97 kB)
    #11 1.568 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 97.4/97.4 kB 32.3 MB/s eta 0:00:00
    #11 1.585 Preparing metadata (setup.py): started
    #11 1.920 Preparing metadata (setup.py): finished with status 'error'
    #11 1.930 error: subprocess-exited-with-error
    #11 1.930
    #11 1.930 × python setup.py egg_info did not run successfully.
    #11 1.930 │ exit code: 1
    #11 1.930 ╰─> [8 lines of output]
    #11 1.930 Traceback (most recent call last):
    #11 1.930 File "<string>", line 2, in <module>
    #11 1.930 File "<pip-setuptools-caller>", line 34, in <module>
    #11 1.930 File "/tmp/pip-install-p7s8jj6d/mariadb_90e5111808594b418ebf9c5df54e9d58/setup.py", line 27, in <module>
    #11 1.930 cfg = get_config(options)
    #11 1.930 File "/tmp/pip-install-p7s8jj6d/mariadb_90e5111808594b418ebf9c5df54e9d58/mariadb_posix.py", line 64, in get_config
    #11 1.930 print('MariaDB Connector/Python requires MariaDB Connector/C '
    #11 1.930 TypeError: not enough arguments for format string
    #11 1.930 [end of output]
    #11 1.930
    #11 1.930 note: This error originates from a subprocess, and is likely not a problem with pip.
    #11 1.933 error: metadata-generation-failed
    #11 1.933
    #11 1.933 × Encountered error while generating package metadata.
    #11 1.933 ╰─> See above for output.
    #11 1.933
    #11 1.933 note: This is an issue with the package mentioned above, not pip.
    #11 1.933 hint: See above for details.
    ------
    executor failed running [/bin/sh -c pip install --no-cache-dir -r requirements.txt]: exit code: 1


    Obviously something isn't right with my MariaDB Connector/C but I don't understand what.

    My understanding is that apt-get install libmariadb3 libmariadb-dev should install the right connector but apparently not(?) so when I looked into trying to install a Connector/C manually into the container before running any of the pip commands, I run into the issue that there is so much choice that I don't understand WHICH connector to download, there are literally hundreds of versions and dozens of files for each, I'm completely lost... what do I need to look for? Where do I need to look? How do I then install?

    Any help would be very much appreciated.

    Continue reading...

Compartilhe esta Página