Problems installing mariadb python connector with "pip install mariadb" in a virtual environment

  • Python 3.9.4
  • Fedora 34 workstation

I want to read data in a mariadb database from a python program.
Environment:

  • The Server is a virtual machine using gnome-boxes.
  • Guest: Centos 8 Stream
    • mariadb version 10.3.27
  • Host, fedora 34:
    • mariadb version 10.5.9

I have a python virtual environment in host:

mkdir connection && cd connection
python -m venv jarvis
source /jarvis/bin/activate

I trying to install mariadb python connector with the following command:

(jarvis) pip install mariadb

But an error occurred

WARNING: Discarding https://files.pythonhosted.org/packages/94/df/1c0d68f2f24b987b2ecb6d46175132b29da15d60a6c51bc65d4de3bf2f9c/mariadb-0.9.53.tar.gz#sha256=6cefbb3be85b932a491025c4ccfa9024cc98947426fbff6b48129e8142ee9de9 (from https://pypi.org/simple/mariadb/) (requires-python:>=3.6). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
  Using cached mariadb-0.9.52.tar.gz (72 kB)
    ERROR: Command errored out with exit status 1:
     command: /home/joe/Documents/python/connector/jarvis-env/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-4jz14rsh/mariadb_c2dcc4da4eb745a9b6788f0f3764994f/setup.py'"'"'; __file__='"'"'/tmp/pip-install-4jz14rsh/mariadb_c2dcc4da4eb745a9b6788f0f3764994f/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-1548avr1
         cwd: /tmp/pip-install-4jz14rsh/mariadb_c2dcc4da4eb745a9b6788f0f3764994f/
    Complete output (12 lines):
    /bin/sh: line 1: mariadb_config: command not found
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-4jz14rsh/mariadb_c2dcc4da4eb745a9b6788f0f3764994f/setup.py", line 24, in <module>
        cfg = get_config(options)
      File "/tmp/pip-install-4jz14rsh/mariadb_c2dcc4da4eb745a9b6788f0f3764994f/mariadb_posix.py", line 49, in get_config
        cc_version = mariadb_config(config_prg, "cc_version")
      File "/tmp/pip-install-4jz14rsh/mariadb_c2dcc4da4eb745a9b6788f0f3764994f/mariadb_posix.py", line 26, in mariadb_config
        raise EnvironmentError(
    OSError: mariadb_config not found.
    Please make sure, that MariaDB Connector/C is installed on your system, edit the configuration file 'site.cfg' and set the 'mariadb_config'
    option, which should point to the mariadb_config utility.
    ----------------------------------------
WARNING: Discarding https://files.pythonhosted.org/packages/d9/70/d5048fa20d2cd986181094cc35ccae284f36e80fe61e2821b79d281b03a2/mariadb-0.9.52.tar.gz#sha256=554e7067ea68430fb7c3b4df1be7c9f2ff3ab7bf806c2d9076f959645e7a96de (from https://pypi.org/simple/mariadb/) (requires-python:>=3.6). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
ERROR: Could not find a version that satisfies the requirement mariadb
ERROR: No matching distribution found for mariadb
WARNING: You are using pip version 21.0.1; however, version 21.1.1 is available.
You should consider upgrading via the '/home/joe/Documents/python/connector/jarvis-env/bin/python -m pip install --upgrade pip' command.

How can we fix that problem and install the mariadb python connector in fedora-34 workstation?

Quick solution
Install those packages:

sudo dnf install mariadb-connector-c-devel gcc python3-devel

Instructive solution

The error message say about

OSError: mariadb_config not found.

Inspect which package provides that

dnf provides mariadb_config
(jarvis-env) [joe@ec connector]$ dnf provides mariadb_config
Last metadata expiration check: 1:36:11 ago on Tue 11 May 2021 11:59:22 AM -05.
mariadb-connector-c-devel-3.1.12-1.fc34.i686 : Development files for mariadb-connector-c
Repo        : fedora
Matched from:
Filename    : /usr/bin/mariadb_config

mariadb-connector-c-devel-3.1.12-1.fc34.x86_64 : Development files for mariadb-connector-c
Repo        : @System
Matched from:
Filename    : /usr/bin/mariadb_config

mariadb-connector-c-devel-3.1.12-1.fc34.x86_64 : Development files for mariadb-connector-c
Repo        : fedora
Matched from:
Filename    : /usr/bin/mariadb_config

Then install the packages

sudo dnf install mariadb-connector-c-devel

That raise another problem. After trying install the mariadb python connector. pip install mariadb

(jarvis-env) [joe@ec connector]$ pip install mariadb
Collecting mariadb
  Using cached mariadb-1.0.6.tar.gz (67 kB)
Using legacy 'setup.py install' for mariadb, since package 'wheel' is not installed.
Installing collected packages: mariadb
    Running setup.py install for mariadb ... error
    ERROR: Command errored out with exit status 1:
     command: /home/joe/Documents/python/connector/jarvis-env/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-vi_xfi7x/mariadb_d2c8d5fd8d5a42a8a420e00b5fc44429/setup.py'"'"'; __file__='"'"'/tmp/pip-install-vi_xfi7x/mariadb_d2c8d5fd8d5a42a8a420e00b5fc44429/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-vcm7ud0p/install-record.txt --single-version-externally-managed --compile --install-headers /home/joe/Documents/python/connector/jarvis-env/include/site/python3.9/mariadb
         cwd: /tmp/pip-install-vi_xfi7x/mariadb_d2c8d5fd8d5a42a8a420e00b5fc44429/
    Complete output (24 lines):
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.9
    creating build/lib.linux-x86_64-3.9/mariadb
    copying mariadb/__init__.py -> build/lib.linux-x86_64-3.9/mariadb
    creating build/lib.linux-x86_64-3.9/mariadb/constants
    copying mariadb/constants/__init__.py -> build/lib.linux-x86_64-3.9/mariadb/constants
    copying mariadb/constants/CLIENT.py -> build/lib.linux-x86_64-3.9/mariadb/constants
    copying mariadb/constants/INDICATOR.py -> build/lib.linux-x86_64-3.9/mariadb/constants
    copying mariadb/constants/CURSOR.py -> build/lib.linux-x86_64-3.9/mariadb/constants
    copying mariadb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-3.9/mariadb/constants
    running build_ext
    building 'mariadb._mariadb' extension
    creating build/temp.linux-x86_64-3.9
    creating build/temp.linux-x86_64-3.9/mariadb
    gcc -pthread -Wno-unused-result -Wsign-compare -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -O2 -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -O2 -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -fPIC -DPY_MARIADB_MAJOR_VERSION=1 -DPY_MARIADB_MINOR_VERSION=0 -DPY_MARIADB_PATCH_VERSION=6 -I/usr/include/mysql -I/usr/include/mysql/mysql -I./include -I/home/joe/Documents/python/connector/jarvis-env/include -I/usr/include/python3.9 -c mariadb/mariadb.c -o build/temp.linux-x86_64-3.9/mariadb/mariadb.o -DDEFAULT_PLUGINS_SUBDIR="/usr/lib64/mariadb/plugin"
    In file included from mariadb/mariadb.c:21:
    ./include/mariadb_python.h:21:10: fatal error: Python.h: No such file or directory
       21 | #include "Python.h"
          |          ^~~~~~~~~~
    compilation terminated.
    error: command '/usr/bin/gcc' failed with exit code 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /home/joe/Documents/python/connector/jarvis-env/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-vi_xfi7x/mariadb_d2c8d5fd8d5a42a8a420e00b5fc44429/setup.py'"'"'; __file__='"'"'/tmp/pip-install-vi_xfi7x/mariadb_d2c8d5fd8d5a42a8a420e00b5fc44429/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-vcm7ud0p/install-record.txt --single-version-externally-managed --compile --install-headers /home/joe/Documents/python/connector/jarvis-env/include/site/python3.9/mariadb Check the logs for full command output.
WARNING: You are using pip version 21.0.1; however, version 21.1.1 is available.
You should consider upgrading via the '/home/joe/Documents/python/connector/jarvis-env/bin/python -m pip install --upgrade pip' command.

The error output say about “Python.h” and gcc. Python.h refers to python devel packages, then install.

sudo dnf install gcc python3-devel

Now run the command successfully.

(jarvis) pip install mariadb

Mariadb python connector will be installed.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.