1

I am trying to use the win32ui module from pywin32 (yes i have the correct version). My win32gui module does work fine but the ui module give me and error. I have already tried: reinstalling python, adding PYTHON_PATH too system vars, running the after install pywin32 script, For the rest I am kinda of out thing i can try to do.

Python version: 3.9 (64 bit) Pywin32 version: pywin32-228.win-amd64-py3.9 (is the .exe file name i don't know how to find the version) just to clear up my only code is:

import win32ui

(this is my first question so i hope i have done this right)

CristiFati
  • 28,721
  • 9
  • 41
  • 63
tovernaar123
  • 178
  • 10
  • Hey Tovenaar Welcome to Stack Overflow. if its possible show some of the output of your script and maybe the smallest example of your script which reproduces the failure. Imagine being a helpful person not sitting at your computer. Help him/her help you. (but also keep it small and up to the point) – studioj Oct 20 '20 at 12:43
  • @studioj my script is simpely import win32ui which errors with: ImportError: DLL load failed while importing win32ui: A dynamic link library (DLL) initialization routine failed. – tovernaar123 Oct 20 '20 at 13:14
  • a quick google brought me here, did you try already? https://github.com/mhammond/pywin32/issues/1431#issuecomment-700104234 => also edit your post add your python version and the pywin32 version – studioj Oct 20 '20 at 14:01
  • @studioj yes i did try install it with pip and also say set the correct version ( just to bu sure i also tried and downloaded the .exe installer and also with that the win32ui still errors) – tovernaar123 Oct 20 '20 at 14:08
  • did you try the pywin32 225 version? pip install pywin32==225 – studioj Oct 20 '20 at 14:16
  • @studioj yes same error – tovernaar123 Oct 20 '20 at 14:31
  • its probably a PATH issue. if you're capable of debugging put a breakpoint in the code figure out which dll its trying to import and verify its in your path (most likely not) – studioj Oct 20 '20 at 15:00
  • @studioj i cant really debug it as its only 1 line and my idle does not tell me anithing when its just 1 line so no i cant really debug it altough i have set my path to inculde /site-packges (ofc i you know any program i need to download that can debug it i would be happy to try that) – tovernaar123 Oct 20 '20 at 15:02
  • a commonly used IDE is pycharm .... but using it properly is not really easy for beginners. you might want to have a look here to help you https://www.jetbrains.com/help/pycharm/debugging-your-first-python-application.html#where-is-the-problem – studioj Oct 20 '20 at 15:41
  • i will look into pycharm i am no bigner per say to coding more to pythong :P – tovernaar123 Oct 20 '20 at 15:53
  • @studioj here is the error: [link] (https://controlc.com/04c01027) – tovernaar123 Oct 20 '20 at 16:24
  • what also could be a problem is that your package is installed for another version of python .... 32/64 bit i've seen this import fail happen before. I'll try running the code myself locally also with those versions validating its not a bug – studioj Oct 20 '20 at 17:35
  • Please post exactly what you've tried and where did you encounter errors. Check [\[SO\]: How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) or [\[SO\]: How to create a Minimal, Reproducible Example (reprex (mcve))](https://stackoverflow.com/help/minimal-reproducible-example) for more asking related details. – CristiFati Oct 20 '20 at 19:11

1 Answers1

2

Update

Applied the (below) fix (and a couple of more) to the original sources, built them, and uploaded the .whls to [GitHub]: CristiFati/Prebuilt-Binaries - (master) Prebuilt-Binaries/PyWin32/v228.
But, since this bug is kind of a "deal breaker" (and there are 4+ months since v228 was released), I'm expecting v229 very soon (in the next days or so).

Check the Install steps section from (the beginning of) [SO]: PyWin32 and Python 3.8.0 (@CristiFati's answer) for details on how to install the .whls.



It's constantly reproducible on:

  • Python 3.9 64bit and 32bit (works on older versions)
  • PyWin32 228 (and older)
[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

I did some debugging (created a VStudio 2015 solution (with 2 projects: for Python 3.9 and Python 3.8) for win32ui), and it turns out it's an Access Violation (segfault).
The "best" part is that it's occurring before DllMain.

One of the last lines that I could get the debugger in, was [GitHub]: mhammond/pywin32 - (b228) pywin32/Pythonwin/win32RichEdit.cpp#225:

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)”?, and I chased some ghosts.

Anyway, today I noticed [GitHub]: mhammond/pywin32 - Ensure we hold the GIL as win32ui initializes and calls back into Python (and from there [GitHub]: mhammond/pywin32 - Import win32ui broken on Python 3.9 that it's addressing).

Applying the patch, fixes the problem:

[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
CristiFati
  • 28,721
  • 9
  • 41
  • 63
  • I have not been able to fix the problem with this ( because i dont know how to build that patch) but you are right as to this being the solution so thanks (ill just wait for the update ) – tovernaar123 Oct 25 '20 at 17:51
  • As I mentioned at the beginning, I built the *v228* sources + this patch + 2 other fixes that were push in the *master* branch after that version was released. You can download the one that you need (most likely the *64bit* one) locally, and install it via *PIP*. – CristiFati Oct 25 '20 at 17:54
  • how would install it via PIP as i cant see any releases after that patch, and the build process does not work as i need build tools for vscode (and i cant seem to find version 14.2 which it needs) – tovernaar123 Oct 25 '20 at 18:01
  • I added a reference to another answer where I briefly explain how to install the *.whl*. Let me know if you encounter any issues. – CristiFati Oct 25 '20 at 18:13
  • @CrisitiFati I just ran install and that seemd to work thanks ( I did test the module does work now ). The build you made was super handy as i cant build it myself. – tovernaar123 Oct 25 '20 at 18:29