[Python] Why can my Pyinstaller EXE not find mysql_native_password from mysql-connector-python?

Discussão em 'Python' iniciado por Stack, Junho 24, 2025.

  1. Stack

    Stack Membro Participativo

    When compiling my application that includes mysql.connector with pyinstaller, attempting to make a database connection in the exe results in this error:

    Traceback (most recent call last):
    File "Report App.py", line 135, in run_report
    File "odbc_config.py", line 32, in run_query_tbred
    File "mysql\connector\pooling.py", line 322, in connect
    File "mysql\connector\connection_cext.py", line 151, in __init__
    File "mysql\connector\abstracts.py", line 1426, in connect
    File "mysql\connector\connection_cext.py", line 335, in _open_connection
    _mysql_connector.MySQLInterfaceError: Authentication plugin 'mysql_native_password' cannot be loaded: The specified module could not be found.


    This issue does NOT happen while running the application through python natively, only after being compiled. I have tested it with cx_freeze AND pyinstaller, both with the same issues.

    I've seen other posts that seem to fix this issue by either installing mysql-connector-python using pip (which I've obviously already done), or by manually importing the module in their code, or by adding a hidden import in the pyinstaller configuration. None of these have worked. I even added a line before the connection in the file of the module where the error is occurring printing out the module. It correctly prints the file location of the module, but still same issue. The module exists but it cannot find it.

    In the mysql module->connector->connection_cext.py on line 334 I added an import manually and printed the module to confirm its imported.

    try:
    from mysql.connector.plugins import mysql_native_password
    print(mysql_native_password)
    self._cmysql.connect(**cnx_kwargs)
    self._cmysql.converter_str_fallback = self._converter_str_fallback
    if self.converter:
    self.converter.str_fallback = self._converter_str_fallback
    except MySQLInterfaceError as err:
    raise get_mysql_exception(
    msg=err.msg, errno=err.errno, sqlstate=err.sqlstate
    ) from err


    This properly prints the location of the module in my temp folder:

    <module 'mysql.connector.plugins.mysql_native_password' from 'C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\_MEI260882\\mysql\\connector\\plugins\\mysql_native_password.pyc'>


    This does not fix the issue though, it still cannot find the mysql_native_password module.

    I've added all of mysql.connector in the hidden import of pyinstaller. It just says it was already imported.

    Attempting any fix from the seemingly duplicate posts results in the same issue. Nothing I've seen has fixed this issue.

    Hidden import, manually importing the module, reinstalling the module. Nothing works.

    This is being done on Windows 11 connecting to a remote database.

    Continue reading...

Compartilhe esta Página