mhammond / pywin32

Python for Windows (pywin32) Extensions
5.06k stars 798 forks source link

PythonService was unable to locate the service manager windows 10 #1987

Open Haislich opened 1 year ago

Haislich commented 1 year ago

I have a python service which has been running in my local machine for quite a lot now and everything works. I was ready to transition to my server and I've been facing some issues with the insallation process. I installed everything accordingly to running as a windows service.

After the installation of the service however the python service stops with error 1053 and with no useful informations. After some digging I discovered that the problem might be related to the service manager.

When trying to run it in order to register it, which shouldn't be needed, the output is :

PythonService was unable to locate the service manager. Please see the event log for details

Which is weird because everything seems in place to me Immagine 2022-12-07 123224

The log states:

The description for Event ID 14 from source Python Service cannot be found. Either the component that raises this event is not installed on your local computer or the installation is corrupted. You can install or repair the component on the local computer.

If the event originated on another computer, the display information had to be saved with the event.

The following information was included with the event: 

<Error getting traceback - traceback.print_exception() failed>

The specified resource type cannot be found in the image file

From the source code of service manager i couldn't trace back the problem since it seems every problem redirects ultimately to this situation.

Haislich commented 1 year ago

Rolling back to python 3.10.5 solves the issue.

JDM-GBG commented 1 year ago

I encountered a similar situation, although I received a different error: https://stackoverflow.com/questions/76174279/module-not-found-error-in-python-script-running-as-a-windows-service

However your fix of reverting to 3.10.x resolved the problem. So it appears there's an incompatibility between Python 3.11 and pywin32, which needs corrected.

PavelPu commented 1 year ago

I suspect it has something to do not only with Python version, but Windows Server as well. I can run my service under Win11, but have same error under Win Server 2019

daniel-airgus commented 1 year ago

This issue seems to persist for 3.10.11 and 3.11.5 is there any way to fix this?

JDM-GBG commented 1 year ago

Issue also persists when using Python 3.12. However using an environment built with 3.10.11, I do not get the error. (This is on a machine running Windows Server 2016.)

jererc commented 1 month ago

I have the same issue (error 1053 when starting the service and the log shows "ModuleNotFoundError: No module named 'servicemanager'") on windows 11. The issue happens on both python 3.12.6 and 3.10.0. The service only runs when not using the virtualenv, on any python version.

Avasam commented 1 month ago

I'll re-open this since "downgrading to a lower Python version" isn't a valid fix and there's multiple reports of this still being an issue.