mhammond / pywin32

Python for Windows (pywin32) Extensions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pywin32_postinstall wrongly identifies a debug build

saevus1991 opened this issue · comments

I was setting up a simple test project to play with python windows services with virtual environment based on this tutorial https://oxylabs.io/blog/python-script-service-guide . While running pywin32_postinstall I got the following error:

RuntimeError: Can not locate the program 'pythonw_d.exe'

It seems that a python debug build was identified even though I used a regular python build. After some digging, I located the issue in the _find_localserver_exe function in the win32com.server.register module. At the beginning of the file, the base .exe is identfied as

def _find_localserver_exe(mustfind):
    if not sys.platform.startswith("win32"):
        return sys.executable
    if pythoncom.__file__.find("_d") < 0:
        exeBaseName = "pythonw.exe"
    else:
        exeBaseName = "pythonw_d.exe"
    ...

pythoncom.file.find("_d") returns the full path. In my case, the project folder containing the virtual environment is named c:/Code/python_windows_service_demo so the "_d" produced a match. This should be easily fixable by only checking the filename instead of the full path, e.g.

if os.path.basename(pythoncom.__file__).find("_d") < 0:

Python: 3.12.2
PyWin32: 306
Steps to reproduce: Follow the tutorial but place your virtual environment in a dir that has "_d" somewhere in its path.

Same as #1949 , fixed by #2169 . Will be included in next release.