Install MariaDB Connector/Python

Overview

MariaDB Connector/Python can be installed in multiple ways.

Dependencies

MariaDB Connector/Python has the following dependencies:

Version

Installation Methods

Connector/C Dependency

Python 3 Dependency

Connector/Python 1.1

  • pip3 (from PyPI)

  • pip3 (from source distribution)

  • Required: Connector/C 3.3.1 or later

  • Required: CPython 3.8 or later

Connector/Python 1.0

  • pip3 (from PyPI)

  • pip3 (from source distribution)

  • Required: Connector/C 3.1.5 or later

  • Required: CPython 3.8 or later

Prerequisites for Source Distributions

When MariaDB Connector/Python is installed from a source distribution, some additional prerequisites are required.

C Compiler

Installing MariaDB Connector/Python from a source distribution requires a C compiler, such as GCC.

On CentOS, RHEL, and Rocky Linux, GCC can be installed with the following command:

$ sudo yum install gcc

On Debian and Ubuntu, GCC can be installed with the following command:

$ sudo apt install gcc

On SLES, GCC can be installed with the following command:

$ sudo zypper install gcc

Python Development Files

Installing MariaDB Connector/Python from a source distribution requires Python development files.

On CentOS, RHEL, and Rocky Linux, Python development files can be installed with the following command:

$ sudo yum install python3-devel

On Debian and Ubuntu, Python development files can be installed with the following command:

$ sudo apt install python3-dev

On SLES, Python development files can be installed with the following command:

$ sudo zypper install python3-devel

TLS Library

Installing MariaDB Connector/Python from a source distribution requires a TLS library, such as OpenSSL or GnuTLS.

On CentOS, RHEL, and Rocky Linux, OpenSSL can be installed with the following command:

$ sudo yum install openssl

On Debian and Ubuntu, OpenSSL can be installed with the following command:

$ sudo apt install openssl

On SLES, OpenSSL can be installed with the following command:

$ sudo zypper install openssl

Install from PyPI

MariaDB Connector/Python can be installed from PyPI:

  1. Install a supported version of Python.

    On Linux distributions, Python can be installed using the operating system's package manager.

    On other operating systems, Python can be downloaded from Python.org

  2. Install MariaDB Connector/C, which is a dependency.

  3. On operating systems other than Microsoft Windows, ensure that that prerequisites for source distributions are met.

    For installations on Microsoft Windows, PyPI installs MariaDB Connector/Python from a Wheel package, which is a package containing pre-built binaries. Therefore, the prerequisites are not required for Windows installations.

  4. Use pip3 to install MariaDB Connector/Python from PyPI.

    To install the latest MariaDB Connector/Python 1.1MariaDB Connector/Python 1.1 release from PyPI:

    $ pip3 install mariadb==1.1.10
    

    To install the latest MariaDB Connector/Python 1.0MariaDB Connector/Python 1.0 release from PyPI:

    $ pip3 install mariadb==1.0.11
    

Install from Source Distribution

  1. Install a supported version of Python.

    On Linux distributions, Python can be installed using the operating system's package manager.

    On other operating systems, Python can be downloaded from Python.org

  2. Install MariaDB Connector/C, which is a dependency.

  3. Ensure that that prerequisites for source distributions are met.

  4. Go to the MariaDB Downloads page

  5. Download a source tarball for a supported MariaDB Connector/Python 1.1MariaDB Connector/Python 1.1 or MariaDB Connector/Python 1.0MariaDB Connector/Python 1.0 release.

  6. Extract the source tarball.

    To extract the source tarball for the latest MariaDB Connector/Python 1.1MariaDB Connector/Python 1.1 release:

    $ mkdir mariadb-connector-python
    $ cd mariadb-connector-python
    $ tar -xvzf ../mariadb-connector-python-1.1.10.tar.gz
    

    To extract the source tarball for the latest MariaDB Connector/Python 1.0MariaDB Connector/Python 1.0 release:

    $ mkdir mariadb-connector-python
    $ cd mariadb-connector-python
    $ tar -xvzf ../mariadb-connector-python-1.0.11.tar.gz
    
  7. Use pip3 to install from the source distribution.

    To install a MariaDB Connector/Python 1.1MariaDB Connector/Python 1.1 or MariaDB Connector/Python 1.0MariaDB Connector/Python 1.0 release from source:

    $ pip3 install ./mariadb-*
    

Test Installation

To test the installation of MariaDB Connector/Python, try to load the module with Python.

On operating systems where Python 3 is installed as python, use the following command:

$ python -c "import mariadb"

On operating systems where Python 3 is installed as python3, use the following command:

$ python3 -c "import mariadb"

If MariaDB Connector/Python was installed correctly, the command returns no output.

If Python can't load MariaDB Connector/Python, the command raises the following error:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'mariadb'