[CONPY-239] "ImportError: Mariadb module initialization failed" upon import of mariadb Created: 2022-11-25  Updated: 2022-12-01  Resolved: 2022-12-01

Status: Closed
Project: MariaDB Connector/Python
Component/s: Generic
Affects Version/s: 1.1.5
Fix Version/s: 1.1.6

Type: Bug Priority: Blocker
Reporter: oskar Assignee: Georg Richter
Resolution: Fixed Votes: 0
Labels: None
Environment:

Pop!_OS 22.04 LTS x64
libmariadb-dev 1:10.6.11-0ubuntu0.22.04.1
libmariadb3 1:10.6.11-0ubuntu0.22.04.1


Issue Links:
Blocks
is blocked by CONPY-240 More detailed error message when load... Closed
Python Version: 3.10

 Description   

When importing the MariaDB module, an exception is thrown for no apparent reason. The code does not continue running.

import mariadb

Traceback (most recent call last):
  File "/home/oskar/Documents/project/mdb.py", line 1, in <module>
    import mariadb
  File "/home/oskar/.cache/pypoetry/virtualenvs/project-WNBj78Lw-py3.10/lib/python3.10/site-packages/mariadb/__init__.py", line 7, in <module>
    from ._mariadb import (
ImportError: Mariadb module initialization failed

The only other occurrence of this I can find online is at https://stackoverflow.com/questions/65011353/problems-with-import-mariadb-python



 Comments   
Comment by Georg Richter [ 2022-11-26 ]

Hi,

Looks like the Connector/C client library was not found.
Could you please provide the following information:

  • Output of

    ldconfig -p -v -N |& grep libmariadb
    

  • Output of

    mariadb_config
    

Comment by oskar [ 2022-11-26 ]

Thank you for looking into this.

$ ldconfig -p -v -N |& grep libmariadb
        libmariadb.so.3 (libc6,x86-64) => /lib/x86_64-linux-gnu/libmariadb.so.3
        libmariadb.so (libc6,x86-64) => /lib/x86_64-linux-gnu/libmariadb.so

$ mariadb_config 
Copyright 2011-2020 MariaDB Corporation AB
Get compiler flags for using the MariaDB Connector/C.
Usage: mariadb_config [OPTIONS]
Compiler: GNU 11.3.0
  --cflags        [-I/usr/include/mariadb -I/usr/include/mariadb/mysql]
  --include       [-I/usr/include/mariadb -I/usr/include/mariadb/mysql]
  --libs          [-L/usr/lib/x86_64-linux-gnu/ -lmariadb]
  --libs_r        [-L/usr/lib/x86_64-linux-gnu/ -lmariadb]
  --libs_sys      [-ldl -lm -lssl -lcrypto]
  --version       [10.6.11]
  --cc_version    [3.3.3]
  --socket        [/run/mysqld/mysqld.sock]
  --port          [3306]
  --plugindir     [/usr/lib/x86_64-linux-gnu/libmariadb3/plugin]
  --tlsinfo       [OpenSSL 3.0.2]
  --variable=VAR  VAR is one of:
      pkgincludedir  [/usr/include/mariadb]
      pkglibdir      [/usr/lib/x86_64-linux-gnu]
      pkgplugindir   [/usr/lib/x86_64-linux-gnu/libmariadb3/plugin]
  --libmysqld-libs  [-L/usr/lib/x86_64-linux-gnu/ -lmariadbd -ldl -lm -lssl -lcrypto]

Comment by Georg Richter [ 2022-11-28 ]

The current implementation of error handling in module initialization is not really optimal. I already filed CONPY-240 and pushed the fix (1.1.6).

Would you mind to try 1.1.6 to get some more information?

1.1.6 is not available yet via pypi - so you need to grab it from github:

git clone https://github.com/mariadb-corporation/mariadb-connector-python.git cc_python
cd cc_python
python3.10 -m pip install .

Comment by oskar [ 2022-11-28 ]

It gets rid of the original exception, however, there is now a new issue:
No code is run after import, PyCharm states

$ python mdb.py
 
Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)

The script I used was:

import mariadb
 
print("mariadb loaded")

Comment by oskar [ 2022-11-30 ]

Upon further experimentation, I discovered that a python file in my directory named numbers.py was at fault for causing the segfault. The MySQL python connector had this listed in a stack trace- this one didn't. The issue is resolved upon renaming or removing the numbers.py file from my directory - keeping this open as the error message is still unclear for anyone else with this issue.

Comment by Georg Richter [ 2022-12-01 ]

Fixed in rev. 03b72c6644e40c37c00cc200aaf7041958990e44 (1.1.6)

georg@beethoven:~/test$ touch numbers.py
georg@beethoven:~/test$ python3.11 -c "import mariadb"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/georg/.local/lib/python3.11/site-packages/mariadb/__init__.py", line 7, in <module>
    from ._mariadb import (
  File "/usr/lib/python3.11/decimal.py", line 3, in <module>
    from _decimal import *
AttributeError: module 'numbers' has no attribute 'Number'

Generated at Thu Feb 08 03:31:17 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.