7

I've been playing around with trying to setup Python scripts (Both .PY and .EXE via Pyinstaller) as Windows Services. My challenge has been that most problems encountered don't seem to relate to my own.

I managed to successfully setup a Virtual Environment once, and get an example service running. However, in documenting my steps, and attempting to recreate the Virtual Environment and running the service I encounter issues.

> python -m venv venv
> venv\scripts\activate.bat
> pip install pypiwin32

Then as instructed in this StackOverflow Question. I followed lindsay.stevens.au's answer with running:

> python myvenv\Scripts\pywin32_postinstall.py -install

Then copying venv\Lib\site-packages\win32\pythonservice.exe to venv\Scripts\pythonservice.exe

I've been using this Service Example from HaroldMils on GitHub as app.py.

When I run this:

> python app.py install
Installing service PythonExample
Service installed

> python app.py debug
Debugging service PythonExample - press Ctrl+C to stop.
Error 0xC0000005 - Python could find the service class in the module

<Error getting traceback - traceback.print_exception() failed

(null): (null)

My previous virtual environment still works, with the exact same script. I've tried removing the virtual environment and trying again, same result. What am I doing wrong? I can't get any more debug info out of this.

On the Virtual Environment that works, I tried uninstalling pypiwin32, reinstalling, it still works.

EDIT: Using Python 3.7.1 32-Bit

sdavis891
  • 101
  • 1
  • 3
  • 10
  • Did you ever find a solution? I am encountering the same issue with Python 3.7.4, pywin32-228 – cmccandless Jul 24 '20 at 14:36
  • 2
    No unfortunately, I gave up on the windows service method and creating a taskbar app that the user has control over. I narrowed it down to the Windows Service not running as the User but as the System. So the relative path to the Virtual Environment and where the site packages were was missing. Hard-coding the path didn't seem to help. I did manage to get a basic service running with no additional components. If you have the capability to build something without any third-party modules you should be fine. Best of Luck! -- Edit: By basic service I mean no VENV. – sdavis891 Jul 29 '20 at 13:39
  • Thanks. I like the idea of a taskbar app for my application; I hadn't thought of that. I had just stumbled upon the "run as user" issue myself, but hadn't had the chance to test a solution. – cmccandless Jul 30 '20 at 14:27

0 Answers0