Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scripting with win32api fails in Python 3.12 #2254

Closed
bkline opened this issue May 8, 2024 · 10 comments · Fixed by #2257
Closed

Scripting with win32api fails in Python 3.12 #2254

bkline opened this issue May 8, 2024 · 10 comments · Fixed by #2257

Comments

@bkline
Copy link

bkline commented May 8, 2024

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

@mhammond
Copy link
Owner

mhammond commented May 9, 2024

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

@bkline
Copy link
Author

bkline commented May 9, 2024

Any way I can assist?

@mhammond
Copy link
Owner

mhammond commented May 9, 2024

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".

@bkline
Copy link
Author

bkline commented May 9, 2024

Thanks, I'll give it a shot.

@bkline
Copy link
Author

bkline commented May 9, 2024

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'

@Avasam
Copy link
Collaborator

Avasam commented May 9, 2024

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.

@Avasam
Copy link
Collaborator

Avasam commented May 9, 2024

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

@bkline
Copy link
Author

bkline commented May 9, 2024

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.

@bkline
Copy link
Author

bkline commented May 9, 2024

Any wild guesses on the timeline for the next release?

@bkline
Copy link
Author

bkline commented May 10, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants