ImportError: DLL load failed while importing IfxPy on Windows with Python3.8

Viewed 659

Python3.8 changed behaviour on Windows: it does not look for dlls in PATH and there is need to add necessary path with os.add_dll_directory, so module can be imported without error. I need to use OpenInformix/IfxPy module and there is already open issue for this.

In meantime I try to fix it by myself, so I added following code to beginning of IfxPy.py

if os.name == 'nt' and hasattr(os, 'add_dll_directory'):
    informixdir = os.getenv('INFORMIXDIR', None)
    if informixdir and os.path.exists(informixdir):
        os.add_dll_directory(os.path.join(informixdir, "bin"))

but after python setup.py install (I clean previous build and build it again), installed IfxPy.py contains only __bootstrap__ function. Log from installation indicates IfxPy.py is generated during installation:

...
byte-compiling build\bdist.win-amd64\egg\IfxPyDbi.py to IfxPyDbi.cpython-38.pyc
creating stub loader for IfxPy.cp38-win_amd64.pyd
byte-compiling build\bdist.win-amd64\egg\IfxPy.py to IfxPy.cpython-38.pyc
creating build\bdist.win-amd64\egg\EGG-INFO
...

So where I should put this code so import IfxPy does not failed?

1 Answers

Add it before you import the IfxPy module:

import os
if 'INFORMIXDIR' in os.environ:
    os.add_dll_directory(os.path.join(os.environ['INFORMIXDIR'],"bin"))
import IfxPy
        
ConStr="Driver={IBM INFORMIX ODBC DRIVER};SERVER=ids1210;DATABASE=stores7;"
conn=IfxPy.connect(ConStr,"informix","ximrofni")
if conn:
      stmt = IfxPy.exec_immediate(conn, "SELECT 'T'::boolean from table(set{1})")
      res = IfxPy.fetch_tuple(stmt)            
      if res[0]:
         print ("0 is true")
      else:
         print ("0 is false")     
                 
Related