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/