7

I am using Linux Ubuntu 18.04 and python 3. I am trying to build a connection between a maria-db and my python scripts. Therefore I have to install the mariadb package.
I have already installed:

sudo apt install mariadb-server

But when i try:

pip install mariadb

I get following error:

Collecting mariadb
  Using cached mariadb-1.0.0.tar.gz (78 kB)

    ERROR: Command errored out with exit status 1:
     command: /home/niklas/Desktop/Stuff/venv/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pycharm-packaging/mariadb/setup.py'"'"'; __file__='"'"'/tmp/pycharm-packaging/mariadb/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-wfnscxnz
         cwd: /tmp/pycharm-packaging/mariadb/
    Complete output (12 lines):
    /bin/sh: 1: mariadb_config: not found
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pycharm-packaging/mariadb/setup.py", line 26, in <module>
        cfg = get_config(options)
      File "/tmp/pycharm-packaging/mariadb/mariadb_posix.py", line 49, in get_config
        cc_version = mariadb_config(config_prg, "cc_version")
      File "/tmp/pycharm-packaging/mariadb/mariadb_posix.py", line 27, in mariadb_config
        "mariadb_config not found.\nPlease make sure, that MariaDB Connector/C is installed on your system, edit the configuration file 'site.cfg' and set the 'mariadb_config'\noption, which should point to the mariadb_config utility.")
    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.
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

Can anybody help me ?

Edit:

I have now been able to connect to the server but not with te mariadb package. (https://linuxhint.com/connect_mariadb_pymysql/)

SebNik
  • 880
  • 3
  • 10
  • 21

4 Answers4

29

Install MariaDB Connector/C, which is a dependency.

sudo apt-get install libmariadb3 libmariadb-dev

Use PIP to install MariaDB Connector/Python.

pip3 install mariadb
Harley
  • 1,305
  • 1
  • 13
  • 28
7

To install mariadb python module, you have to install a recent version of MariaDB Connector/C, minimum required version is 3.1.5, afaik Ubuntu 18.04 has 3.0.3.

An actual version of Connector/C for bionic is available on the MariaDB Connector/C Download Page.

If you want to install it in a special directory, make sure that the PATH and LD_LIBRARY_PATH point to bin and lib directories.

I also recommend to use a recent version of MariaDB Server, especially the very fast executemany() method will be much slower on MariaDB Server < 10.2.

Georg Richter
  • 5,970
  • 2
  • 9
  • 15
  • Assuming you extracted the Connector/C to: `/usr/local/src/mariadb-connector/mariadb-connector-c-3.1.12-debian-buster-amd64` then you can run this command: `PATH=/usr/local/src/mariadb-connector-c-3.1.12-debian-buster-amd64/bin:$PATH LD_LIBRARY_PATH=/usr/local/src/mariadb-connector-c-3.1.12-debian-buster-amd64/lib:$LD_LIBRARY_PATH pip3 install mariadb` – Felicia Mar 14 '21 at 08:48
0

Before proceeding with the pip install mariadb, try to execute the below command and install the necessary dependencies. Then after, use the pip command to install the MariaDB package.

sudo apt-get install python3-dev
-1

It seems you need to install it first on your OS. You can follow this guide to install it properly.

  • I have follwed that guide and still have the same problem – SebNik Jun 25 '20 at 22:16
  • You needn't install the whole MariaDB server just to have Python connect to it. The Q requires the user to install just the mariadb connector. The DB may not be on the same server as the Python program. – Joseph Oct 25 '20 at 23:41