我正在尝试使用 PythonService.exe
调试我的服务,但出现了一个奇怪的错误:
PS C:\Users\rs_al\Dev\PyXLSQL> py serviceapp.py install
Installing service pyxlsql
Changing service configuration
Service updated
PS C:\Users\rs_al\Dev\PyXLSQL> py serviceapp.py debug
Debugging service pyxlsql - press Ctrl+C to stop.
Error 0xC0000004 - Python could not import the service's module
ModuleNotFoundError: No module named 'w32service'
(null): (null)
项目结构
serviceapp.py
w32service\
__init__.py
service.py
如果我将整个代码从 service.py
移动到 serviceapp.py
中,我就可以毫无问题地调试它。
编辑:
gui.py
gui\
__init__.py
menu.py
pageone.py
pagetwo.py
pagethree.py
它可以完美地作为 *.py
或 .*exe
最佳答案
Python 解释器不知道在哪里查找您的 w32service 模块(包)。一种方法是将其路径添加到 [Python 3.Docs]: Modules - The Module Search Path (导入之前):
import sys
import os
sys.path.append(os.path.abspath(os.path.dirname(__file__)))
from w32service.service import WinService
# ...
为了让事情更清楚,请在导入任何内容(好吧,除了sys)之前使用print(sys.path)
来查看Python在哪里> 搜索模块。
关于python - 无法调试pywin32服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54417608/