nickpick nickpick - 4 months ago 251
Python Question

Pyinstaller: cx_Oracle.InterfaceError: Unable to acquire Oracle environment handle

I have a simple python script that imports cx_Oracle and then makes an sql query. It all works fine when run from python. I have Oracle SQL developer installed on my computer, which is free.

When I then compile the program with 'pyinstaller main.py' everything compiles fine and i can also start the problem. But as soon as an SQL query is made from that program, the following runtime error occurs:

cx_Oracle.InterfaceError: Unable to acquire Oracle environment handle

I have tried the following:


  • moving all .dll and .jar files from oracle to the build directory as here: https://sourceforge.net/p/cx-oracle/mailman/cx-oracle-users/thread/g7nbks$tl$1@ger.gmane.org/

  • excluding oci.dll with the pyinstaller main.py --exclude oci.dll option from pyinstaller

  • checked that my ORACLE_HOME is set correctly to: - C:\Users\nyname\AppData\Local\Continuum\Anaconda3\Lib\site-packages\instantclient_12_1



None of this has worked.

Any suggestions what else I can do are much appreciated.

Answer

I found the solution:

When running pyinstaller as normal one file will be missing in the complication. It needs to be manually included:

For that you need to edit the line with as follows:

binaries+[('oraociei12.dll','oraociei12.dll','BINARY')],

make sure that oraociei12.dll is in the current folder.

block_cipher = None
    a = Analysis(['LDM-shark.py'],
                 pathex=['C:\\Users\\dicknic\\AppData\\Local\\Home\\dev\\LDM'],
                 binaries=None,
                 datas=None,
                 hiddenimports=[],
                 hookspath=[],
                 runtime_hooks=[],
                 excludes=[],
                 win_no_prefer_redirects=False,
                 win_private_assemblies=False,
                 cipher=block_cipher)
    pyz = PYZ(a.pure, a.zipped_data,
                 cipher=block_cipher)
    exe = EXE(pyz,
              a.scripts,
              a.binaries+[('oraociei12.dll','oraociei12.dll','BINARY')],
              a.zipfiles,
              a.datas,
              name='mainprogram',
              debug=False,
              strip=False,
              upx=True,
              console=True )

In a second step run pyinstaller again but with the spec file. pyinstaller mainprogram.spec

and it will work

Comments