尝试将 win32ui 与 pywin32 一起使用会给出: 动态链接库 (DLL) 初始化例程失败

2024-02-28

我正在尝试使用 pywin32 中的 win32ui 模块(是的,我有正确的版本)。 我的 win32gui 模块工作正常,但 ui 模块给我错误。 我已经尝试过: 重新安装Python, 添加 PYTHON_PATH 系统变量, 运行安装后的 pywin32 脚本, 对于其余的事情,我有点无法尝试做。

Python版本:3.9(64位) Pywin32版本:pywin32-228.win-amd64-py3.9(是.exe文件名我不知道如何找到版本) 只是为了清理我唯一的代码是:

import win32ui

(这是我的第一个问题,所以我希望我做对了)


Update

将(下面的)修复(以及更多)应用于原始源,构建它们,并上传.whls to [GitHub]:CristiFati/Prebuilt-Binaries - (主)Prebuilt-Binaries/PyWin32/v228 https://github.com/CristiFati/Prebuilt-Binaries/tree/master/PyWin32/v228.
但是,由于这个错误是一种“交易破坏者”(并且有4+几个月以来v228被释放),我期待着v229很快(在接下来的几天左右)。

检查安装步骤部分(开头)[SO]:PyWin32 和 Python 3.8.0(@CristiFati 的回答) https://stackoverflow.com/a/58632354/4788546有关如何安装的详细信息.whls.



它可以不断地重现:

  • Python 3.9 64bit and 32bit(适用于旧版本)

  • PyWin32 228(以及更老的)

[cfati@CFATI-5510-0:e:\Work\Dev\GitHub\CristiFati\pywin32\src]> sopr.bat
### Set shorter prompt to better fit when pasted in StackOverflow (or other) pages ###

[prompt]> "e:\Work\Dev\VEnvs\py_pc064_03.09.00_test0\Scripts\python.exe"
Python 3.9.0 (tags/v3.9.0:9cf6752, Oct  5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import win32ui
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "c:\Install\pc064\Python\Python\03.09.00\Lib\ctypes\__init__.py", line 374, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 1114] A dynamic link library (DLL) initialization routine failed
>>> import win32api

我做了一些调试(创建了一个VStudio 2015解决方案(有2个项目:用于Python 3.9 and Python 3.8) for win32ui),事实证明这是一个访问违规 (segfault).
“最好”的部分是它正在发生before DllMain.

我可以输入调试器的最后一行之一是[GitHub]: mhammond/pywin32 - (b228) pywin32/Pythonwin/win32RichEdit.cpp#225 https://github.com/mhammond/pywin32/blob/b228/Pythonwin/win32RichEdit.cpp#L225:

PyCCtrlView_Type PyCRichEditView::type("PyCRichEditView", &PyCCtrlView::type, &PyCRichEditCtrl::type,
                                       RUNTIME_CLASS(CRichEditView), sizeof(PyCRichEditView),
                                       PYOBJ_OFFSET(PyCRichEditView), PyCRichEditView_methods,
                                       GET_PY_CTOR(PyCRichEditView));

This is a static member. Since the 2nd and 3rd arguments are also static members (wasn't paying attention to the fact that they're pointers), I thought it was [ISOCPP]: What’s the “static initialization order ‘fiasco’ (problem)”? https://isocpp.org/wiki/faq/ctors#static-init-order, and I chased some ghosts.

无论如何,今天我注意到了[GitHub]:mhammond/pywin32 - 确保我们在 win32ui 初始化并回调 Python 时持有 GIL https://github.com/mhammond/pywin32/commit/a58d0a47b5201f7347afa7465e1a74a623173c6d#diff-463277b58680e924d2eb3486c5ffcdfece92520a691a54d2fd217f20ef166663(然后从那里[GitHub]:mhammond/pywin32 - 导入 win32ui 在 Python 3.9 上损坏 https://github.com/mhammond/pywin32/issues/1593它正在寻址)。

应用补丁,修复问题:

[prompt]> "e:\Work\Dev\VEnvs\py_pc064_03.09.00_test0\Scripts\python.exe"
Python 3.9.0 (tags/v3.9.0:9cf6752, Oct  5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import win32ui
>>> import win32api
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

尝试将 win32ui 与 pywin32 一起使用会给出: 动态链接库 (DLL) 初始化例程失败 的相关文章

随机推荐