Search code examples
pythonwindowsoracle-databasepyinstaller

Packaging Issues PyInstaller of Python application with Oracle Database Connection


I am trying to package a python application using pyinstaller. I am using cx_oracle and the oracle instant client to connect to an oracle database. I am working on Windows 10. My application works fine before I package it. But after packaging, the following error occurs when I try to run the executable file:

cx_Oracle.DatabaseError: DPI-1072: the Oracle Client library version is unsupported

This error occurs in the line cx_Oracle.init_oracle_client(lib_dir=r"instantclient_19_9"). According to the ODPI log, the Oracle Instant Client is loaded successfully, but while validating, the error occurs. The problem is not due to a different Oracle Instant Client version on the system. I have checked for other versions on the systems, but there are none. Also, when I remove the Oracle Instant Client that I am trying to load, a different error occurrs, which says that not Oracle Instant client was found. When I package the application while mocking or omitting the database connection, the packaging works fine.

I have tried everything on two separate systems, on which I experience the same issues. Another person could reproduce my issues as well. Also, I can replicate this error with the following toy example:

There needs to be no Oracle database present. The Oracle Instant Client needs to be installed into the folder where the following file is located.

import cx_Oracle

if __name__ == "__main__":
    cx_Oracle.init_oracle_client(lib_dir=r"instantclient_19_9")

How I packaged:

  • Go to some folder, to which you want to package the application. I'll call it ministaller.
  • Make sure it is empty.
  • python -m PyInstaller --name application C:\path\to\application.py
  • python -m PyInstaller application.spec
  • The exe is located in ministaller\dist\applicationfolder. Call it via cmd to see the error message.

Solution

  • I posted this question on the PyInstaller GitHub, and the answer given there solved the problem for me: https://github.com/pyinstaller/pyinstaller/issues/5572