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.
它可以不断地重现:
[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