Install MariaDB Connector/Python
This page is part of MariaDB's Documentation.
The parent of this page is: MariaDB Connector/Python
Topics on this page:
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 |
|
|
|
Connector/Python 1.0 |
|
|
|
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:
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
Install MariaDB Connector/C, which is a dependency.
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.
Use
pip3
to install MariaDB Connector/Python from PyPI.To install the latest
release from PyPI:$ pip3 install mariadb==1.1.10
To install the latest
release from PyPI:$ pip3 install mariadb==1.0.11
Install from Source Distribution
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
Install MariaDB Connector/C, which is a dependency.
Ensure that that prerequisites for source distributions are met.
Go to the MariaDB Downloads page
Download a source tarball for a supported
or release.Extract the source tarball.
To extract the source tarball for the latest
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
release:$ mkdir mariadb-connector-python $ cd mariadb-connector-python $ tar -xvzf ../mariadb-connector-python-1.0.11.tar.gz
Use
pip3
to install from the source distribution.To install a
or 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'