mhammond / pywin32

Python for Windows (pywin32) Extensions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Scripting with win32api fails in Python 3.12

bkline opened this issue · comments

Expected behavior

Module win32api imports successfully in Windows scripting (as it does in Python 3.11).

Actual behavior

Attempting to import win32api raises an exception.

Steps to reproduce the problem

  1. Install Python 3.12 on a Windows machine.
  2. Install pywin32 release 306.
  3. Register Python as a scripting language: py %PYTHON_DIR%\lib\site-packages\win32comext\axscript\client\pyscript.py.
  4. Run the following test script with cscript test.pys and see ModuleNotFoundError exception ("No module named 'imp'").
print("The 'debugging is disabled' message can be ignored.")
print("Importing win32api")
import win32api
print("Registration of Python Windows scripting successful.")

System information

Python version and distribution:
3.12.3 from https://www.python.org/downloads/

pywin32 version:
306 (Installed from PyPI)

Windows Version:
Microsoft Windows [Version 10.0.19045.4291]

DLL locations:
C:\Python312\Lib\site-packages\pywin32_system32\pywintypes312.dll
C:\Python312\Lib\site-packages\pywin32_system32\pythoncom312.dll

pywin32 needs a new release, which I'm still working out how to do, sorry about that.

Any way I can assist?

Not really, but there are unreleased versions available from every change - eg, the latest can be found at https://github.com/mhammond/pywin32/actions/runs/8890105083, where you can scroll down and download the "artifacts".

Thanks, I'll give it a shot.

I pulled pywin32-306-cp312-cp312-win_amd64.whl from that set and installed it with

py -m pip install --force-reinstall pywin32-306-cp312-cp312-win_amd64.whl

However, when I tried registering Python as a scripting language (step 3 in the repro instructions above), I hit an exception complaining that pythonw_d.exe could not be found. Is it possible that those artifacts are built with debugging versions of the package? This step succeeded with the release version of pywin32.

C:\Users\bkline\Desktop\CdrSetup17\PythonFiles>py C:\Python312\lib\site-packages\win32comext\axscript\client\pyscript.py  1>>pyscript.log
Traceback (most recent call last):
  File "C:\Python312\lib\site-packages\win32comext\axscript\client\pyscript.py", line 443, in <module>
    Register()
  File "C:\Python312\lib\site-packages\win32comext\axscript\client\pyscript.py", line 436, in Register
    ret = win32com.server.register.UseCommandLine(
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\site-packages\win32com\server\register.py", line 648, in UseCommandLine
    RegisterClasses(*classes, **flags)
  File "C:\Python312\Lib\site-packages\win32com\server\register.py", line 464, in RegisterClasses
    RegisterServer(
  File "C:\Python312\Lib\site-packages\win32com\server\register.py", line 272, in RegisterServer
    exeName = _find_localserver_exe(1)
              ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\site-packages\win32com\server\register.py", line 125, in _find_localserver_exe
    raise RuntimeError("Can not locate the program '%s'" % exeBaseName)
RuntimeError: Can not locate the program 'pythonw_d.exe'

To address the original post, this would be a duplicate of #2104 and has been fixed by #2113

I'm working on writing the huge changelog from all my recent changes. I can at least help with that, concerning the next release.

As for your second issue, I think I flipped the condition accidentally in https://github.com/mhammond/pywin32/pull/2169/files#diff-cb7b8aef3604d303af86f90cf1bbc9ad12ff857e8fba1f537fe429fef7e3e9e5R100 , should be an easy fix

Right. Just change line 100 of register.py to if not ... (or swap lines 101 and 103). Adjusting for possible line number drift in later commits.

Any wild guesses on the timeline for the next release?

I have tested PR #2257 and I can confirm that it fixes the last failure I reported, and running the artifacts produced for that run also eliminates the first failure reported by this ticket. We're still hoping for some information on when we should expect a new release.