如何解决带有conda env的python windows_service在numpy上引发导入错误
就像this person一样,我希望使用conda环境来提供Windows服务。
我的服务非常简单。我唯一想测试的就是pytorch是否正确导入:
sfdx force:apex:test:run --codecoverage -r json --classnames "Test_1,Test_2,.....,Test_10" -u testOrg --outputdir path/to/folder
我有一个conda环境,可以在powershell中使用它。
import socket
import servicemanager
import torch
import win32event
import win32service
import win32serviceutil
class SMWinservice(win32serviceutil.ServiceFramework):
_svc_name_ = "TestService"
_svc_display_name_ = "TestService"
_svc_description_ = "TestService delete later"
@classmethod
def parse_command_line(cls):
win32serviceutil.HandleCommandLine(cls)
def __init__(self,args):
win32serviceutil.ServiceFramework.__init__(self,args)
self.hWaitStop = win32event.CreateEvent(None,None)
socket.setdefaulttimeout(60)
def SvcStop(self):
self.stop()
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
win32event.SetEvent(self.hWaitStop)
def SvcDoRun(self):
self.start()
servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE,servicemanager.PYS_SERVICE_STARTED,(self._svc_name_,''))
self.main()
def start(self):
x = torch.empty(5,3)
with open("mypath\\start.txt",'w') as file:
file.write(x)
def stop(self):
with open("mypath\\stop.txt",'w') as file:
file.write("stop")
def main(self):
with open("mypath\\main.txt",'w') as file:
file.write("main")
if __name__ == '__main__':
SMWinservice.parse_command_line()
现在我安装了该服务:
conda activate my_env
python
>>>import torch
>>>torch.empty(5,3)
这很好。现在,当我启动该服务时,我得到一个错误:
python myService.py install
I am not the first one who has this error显然,许多人在安装了两个版本的numpy时都遇到了问题。
Python could not import the service's module
Traceback (most recent call last):
File "my_path_to_project\serviceCondaTest\main.py",line 2,in <module>
import torch
File "my_conda_path\anaconda3\envs\my_env\lib\site-packages\torch\__init__.py",line 81,in <module>
from torch._C import *
ImportError: numpy.core.multiarray failed to import
应该是找到正在使用的版本的方法,但是当我打印numpy版本时,会得到我想要的版本以及通往我的环境的正确路径。我找不到第二个Numpy版本。
怎么了?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。