OpenInformix / IfxPy

Informix native Python driver for scalable enterprise and IoT solutions.
Other
46 stars 22 forks source link

ImportError: DLL load failed while importing IfxPy: The specified module could not be found. #41

Open zdenop opened 4 years ago

zdenop commented 4 years ago

Is there a way how to debug this error message? I read other similar issues and IMO I have set all I need.

I try to build/use with python3.8 and vs2019. I build it this way:

set INFORMIXDIR=c:\Program Files\IBM Informix Client SDK
SET PATH=%INFORMIXDIR%\bin;%PATH%
SET CSDK_HOME=%INFORMIXDIR%
SET MY_PY_DIR=f:/Developments/Python-3.8.4
SET VS90COMNTOOLS=%VS140COMNTOOLS%
"c:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat"
python setup.py build
python setup.py install
Detected 64-bit Python
running install
running bdist_egg
running egg_info
writing IfxPy.egg-info\PKG-INFO
writing dependency_links to IfxPy.egg-info\dependency_links.txt
writing top-level names to IfxPy.egg-info\top_level.txt
reading manifest file 'IfxPy.egg-info\SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'IfxPy.egg-info\SOURCES.txt'
installing library code to build\bdist.win-amd64\egg
running install_lib
running build_py
running build_ext
creating build\bdist.win-amd64\egg
copying build\lib.win-amd64-3.8\IfxPy.cp38-win_amd64.pyd -> build\bdist.win-amd64\egg
copying build\lib.win-amd64-3.8\IfxPyDbi.py -> build\bdist.win-amd64\egg
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
copying IfxPy.egg-info\PKG-INFO -> build\bdist.win-amd64\egg\EGG-INFO
copying IfxPy.egg-info\SOURCES.txt -> build\bdist.win-amd64\egg\EGG-INFO
copying IfxPy.egg-info\dependency_links.txt -> build\bdist.win-amd64\egg\EGG-INFO
copying IfxPy.egg-info\top_level.txt -> build\bdist.win-amd64\egg\EGG-INFO
writing build\bdist.win-amd64\egg\EGG-INFO\native_libs.txt
zip_safe flag not set; analyzing archive contents...
__pycache__.IfxPy.cpython-38: module references __file__
creating 'dist\IfxPy-3.0.3-py3.8-win-amd64.egg' and adding 'build\bdist.win-amd64\egg' to it
removing 'build\bdist.win-amd64\egg' (and everything under it)
Processing IfxPy-3.0.3-py3.8-win-amd64.egg
creating c:\program files\python38\lib\site-packages\IfxPy-3.0.3-py3.8-win-amd64.egg
Extracting IfxPy-3.0.3-py3.8-win-amd64.egg to c:\program files\python38\lib\site-packages
Adding IfxPy 3.0.3 to easy-install.pth file

Installed c:\program files\python38\lib\site-packages\ifxpy-3.0.3-py3.8-win-amd64.egg
Processing dependencies for IfxPy==3.0.3
Finished processing dependencies for IfxPy==3.0.3

Then I run:

python tests\test_000_PrepareDb.py
Traceback (most recent call last):
  File "tests\test_000_PrepareDb.py", line 8, in <module>
    import IfxPy
ImportError: DLL load failed while importing IfxPy: The specified module could not be found.
jsagrera commented 4 years ago

Not sure why the install in your output shows 'C:\program files', in theory it should be whatever you have in your MY_PY_DIR. anyway, try copying the pyd from the build directory to your current dir:

D:\Infx\OpenInformix\IfxPy\IfxPy>cp build\lib.win-amd64-3.7\IfxPy.cp37-win_amd64.pyd IfxPy.pyd

on Windows, you can use something like ProcessMonitor when dealing which such errors. It will help you to find out which file or library failed to load, and which path is been used.

zdenop commented 4 years ago

my python instalation is on C: driver. in MY_PY_DIR there is python source code.

zdenop commented 4 years ago

I found problem:

image

For some reason import IfxPy does not try load informix dlls from C:\Program Files\IBM Informix Client SDK\bin\, even I add it to path (I checked it with echo %path% or running ilogin, esqlfrom command line). How to fix this?

zdenop commented 4 years ago

So there is change of python3.8 behavior on windows: it does not look for dlls in path. Also other projects has problem with it (e.g. https://bugs.python.org/issue36085). There are two way how to fix it:

  1. to include the dependencies/dlls to the IfxPy instalation (maybe on destination computer there will be not need to install CSDK?)
  2. to implement some logic like this before loading dlls:
    
    import os

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"))