Today I tried to use these python packages:
import win32serviceutil
import win32service
import win32event
import servicemanagerThe works , but python -m pywin32_postinstall -install comes with:
python.exe: No module named pywin32_postinstall
NOTE : The copilot artificial intelligence, search and give me an old answer , but is wrong ...
PyWin32 is updated slowly, and at this moment there are no wheels for Python 3.13.
The pip tool cannot install pywin32 does not install anything usable, and pywin32_postinstall does not exist
Possible solutions
PyWin32 works perfectly on:
- Python 3.12
- Python 3.11
- Python 3.10
If you need win32service, win32api, win32com, etc., you must use a supported version.
Need to see the last tutorial from my blogger.
I tested on admin with simple service and works:
python service_test_001.py install
Installing service MyPythonService
Service installedThis is the source code:
import win32serviceutil
import win32service
import win32event
import servicemanager
import time
class MyService(win32serviceutil.ServiceFramework):
_svc_name_ = "MyPythonService"
_svc_display_name_ = "My Python Windows Service"
_svc_description_ = "A minimal Windows service example written in Python."
def __init__(self, args):
win32serviceutil.ServiceFramework.__init__(self, args)
self.stop_event = win32event.CreateEvent(None, 0, 0, None)
self.running = True
def SvcStop(self):
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
win32event.SetEvent(self.stop_event)
self.running = False
def SvcDoRun(self):
servicemanager.LogInfoMsg("MyPythonService is starting.")
self.main()
def main(self):
while self.running:
# Your service logic goes here
time.sleep(5)
servicemanager.LogInfoMsg("MyPythonService heartbeat.")
if __name__ == '__main__':
win32serviceutil.HandleCommandLine(MyService)