【问题标题】:import win32service, win32api, win32con, winerror ImportError: DLL load failed: The specified module could not be foundimport win32service, win32api, win32con, winerror ImportError: DLL load failed: 找不到指定的模块
【发布时间】:2020-06-30 21:26:12
【问题描述】:

我在尝试创建微软服务,但是出现了这个错误,全名错误:

“文件“PythonCornerExample.py”,第 1 行,在 导入 win32serviceutil 文件“C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\win32\lib\win32serviceutil.py”,第 9 行,在 导入 win32service、win32api、win32con、winerror

ImportError: DLL load failed: 找不到指定的模块。”。

我已经尝试安装 Visual C++ Redistributable 2015,但错误仍然存​​在。

这是代码:

import win32service
import win32event
import servicemanager
import socket


class AppServerSvc (win32serviceutil.ServiceFramework):
    _svc_name_ = "TestService"
    _svc_display_name_ = "Test Service"

    def __init__(self,args):
        win32serviceutil.ServiceFramework.__init__(self,args)
        self.hWaitStop = win32event.CreateEvent(None,0,0,None)
        socket.setdefaulttimeout(60)

    def SvcStop(self):
        self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
        win32event.SetEvent(self.hWaitStop)

    def SvcDoRun(self):
        servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE,
                              servicemanager.PYS_SERVICE_STARTED,
                              (self._svc_name_,''))
        self.main()

    def main(self):
        pass

if __name__ == '__main__':
    win32serviceutil.HandleCommandLine(AppServerSvc)```

【问题讨论】:

  • 看起来您已经安装了适用于 Windows 的 32 位版本的 Python,但您正尝试从 64 位 Python 解释器运行它,反之亦然。 Windows 可执行文件无法加载不同位数的 DLL。

标签: python


【解决方案1】:

你只需要重新安装64位的python

链接: https://www.python.org

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-09
    • 1970-01-01
    • 1970-01-01
    • 2020-12-04
    • 2020-07-02
    • 2020-06-30
    • 2015-12-16
    • 2019-08-06
    相关资源
    最近更新 更多