我正在将一个为Python2设计的swig扩展模块移植到Windows10下的Python3,使用的是一个普通的Python3.9.1。该模块可以正确构建,并且依赖于我打包到数据目录中的几个Windows动态加载库(*.dll)。
导入模块失败,并且使用gflag跟踪该问题显示没有加载依赖的dll,因为搜索路径不包括模块名称:lib/site-package/dbxml。当我手动将dll移到lib/site包中时,可以找到并成功加载它们。
我对如何修改安装程序以生成包含模块名称的DLL路径感到困惑。我看到this post似乎暗示我可以简单地使用data_files选项,但这在我的情况下似乎不起作用。
以下是我正在对我认为是相关变量的值所做的操作:
setup(name = "dbxml",
version = "6.1.4",
description = "Berkeley DB XML Python API",
long_description = """removed...""",
author = "Oracle",
author_email = "berkeleydb-info_us@oracle.com",
url = "http://www.oracle.com",
py_modules = ["dbxml"],
ext_modules = [Extension("_dbxml", ["dbxml_python3_wrap.cpp"],
include_dirs = INCLUDES,
library_dirs = ['../../../lib', '../../build_windows/Release',
'../../../db-6.2.23/build_windows/Release',
'../../../xqilla/lib',
'../../../xerces-c-src/Build/Win32/VC10'],
define_macros = DEFINES,
libraries = ['libdbxml61', 'libdb62', 'xqilla23', 'xerces-c_3'],
extra_compile_args = ['/GR', '/EHsc']
)],
# The DLLs below are copied into lib/site-packages/dbxml
# but the DLL search path is:
# C:\Users\[...omitted...]\python3.9\lib\site-packages;
# C:\Users\[...omitted...]\python3.9;
# C:\WINDOWS\SYSTEM32
# and they are not found.
data_files = [('lib/site-packages/dbxml',
['../../../bin/libdbxml61.dll',
'../../../bin/libdb62.dll',
'../../../bin/xqilla23.dll',
'../../../bin/xerces-c_3_1.dll',
'../../build_windows/zlib1.dll',
'../../build_windows/zlibwapi.dll'
])
]
)我的理解是,扩展的runtime_library_dirs关键字参数在类UNIX操作系统上只控制运行时库路径,在Windows10上被忽略。显然,我做错了什么。任何关于如何解决这个问题的建议都将不胜感激。
谢谢你-玛丽
发布于 2021-03-14 01:37:27
看来DLL library loading behavior changed in Python 3.8. .。必须使用os模块函数add_dll_directory显式设置Windows中DLL的路径。我可以通过添加以下内容来解决此问题:
# add peer directory to dll search path
import os
dll_dir = os.path.join(os.path.dirname(__file__), "dbxml")
os.add_dll_directory(dll_dir)也许有一种更好的方法可以做到这一点,但这将允许扩展模块从站点包中的对等目录加载动态链接库。
https://stackoverflow.com/questions/66591019
复制相似问题