python-3.x - 导入错误 : DLL load failed while importing IfxPy on Windows with Python3. 8

标签 python-3.x windows informix

Python3.8 在 Windows 上改变了行为:它不在 PATH 中查找 dll,需要使用 os.add_dll_directory 添加必要的路径,因此可以正确导入模块。我需要使用 OpenInformix/IfxPy 模块并且已经有 open issue for this .
同时我尝试自己修复它,所以我在 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"))
但在 python setup.py install 之后(我清理了之前的构建并再次构建它),安装 IfxPy.py仅包含 __bootstrap__功能。
安装日志显示 IfxPy.py在安装过程中生成:
...
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
...
所以我应该把这段代码放在哪里import IfxPy不失败?

最佳答案

在导入 IfxPy 模块之前添加它:

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

关于python-3.x - 导入错误 : DLL load failed while importing IfxPy on Windows with Python3. 8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63285306/

相关文章:

python - 使用 pycountry 检查 name/common_name/official_name

python - 字符串类型变量的自定义千位分隔符

javascript - Electron -如何处理多台显示器的屏幕窗口?

windows - 如何记录批处理文件中删除了多少数据

informix - 如何设置解释选项?

sql - 有没有办法在不写查询中所有字段名称的情况下选择第一个表?

python - 基于多键或多键组合或合并字典

python - 机器学习随机森林

c++ - win 7可以设置单步陷阱吗?

database - 如何从 Informix 中的名称获取约束详细信息?