在 Azure Functions 的脚本中导入 python-tabular 时出现错误

问题描述 投票:0回答:1

我有用于连接SSAS模型进行分区创建、删除和刷新的脚本。在这里,对于分区创建和删除,我使用名为 pyadomd 的库。

为了刷新,我使用名为 python-tabular 的库。 https://pypi.org/project/python-tabular/0.1.7/

我已将代码部署到 Azure Function 中,当我尝试触发该函数时,我在 import 语句 --> import pytabular 中收到错误。以下是完整的异常,请帮我解决这个问题,

Full Exception :
 Exception while executing function
 /Functions.httpTrigger ---> Microsoft.Azure.WebJobs.Script.Workers.Rpc.RpcException 
 /Result
 /Failure Exception
 /RuntimeError
 /Could not find libmono 

 /  
 '/azure-functions-host/workers/python/3.10/LINUX/X64/azure_functions_worker/dispatcher.py', line 380, in _handle__function_load_request     func = loader.load_function(   
 '/azure-functions-host/workers/python/3.10/LINUX/X64/azure_functions_worker/utils/wrappers.py', line 44, in call     return func(*args, **kwargs)   
 '/azure-functions-host/workers/python/3.10/LINUX/X64/azure_functions_worker/loader.py', line 132, in load_function     mod = importlib.import_module(fullmodname)   
 '/usr/local/lib/python3.10/importlib/__init__.py', line 126, in import_module     return _bootstrap._gcd_import(name[level:], package, level)   
 '<frozen importlib._bootstrap>', line 1050, in _gcd_import   
 '<frozen importlib._bootstrap>', line 1027, in _find_and_load   
 '<frozen importlib._bootstrap>', line 1006, in _find_and_load_unlocked   
 '<frozen importlib._bootstrap>', line 688, in _load_unlocked   
 '<frozen importlib._bootstrap_external>', line 883, in exec_module   
 '<frozen importlib._bootstrap>', line 241, in _call_with_frames_removed   
 '/home/site/wwwroot/httpTrigger/__init__.py', line 9, in <module>     from .refresh_automation import main_func   
 '/home/site/wwwroot/httpTrigger/refresh_automation.py', line 6, in <module>     import pytabular   
 '/home/site/wwwroot/.python_packages/lib/site-packages/pytabular/__init__.py', line 45, in <module>     import clr   
 '/home/site/wwwroot/.python_packages/lib/site-packages/clr.py', line 6, in <module>     load()   
 '/home/site/wwwroot/.python_packages/lib/site-packages/pythonnet/__init__.py', line 36, in load     set_default_runtime()   
 '/home/site/wwwroot/.python_packages/lib/site-packages/pythonnet/__init__.py', line 22, in set_default_runtime     set_runtime(clr_loader.get_mono())   
 '/home/site/wwwroot/.python_packages/lib/site-packages/clr_loader/__init__.py', line 21, in get_mono     libmono = find_libmono(sgen)   
 '/home/site/wwwroot/.python_packages/lib/site-packages/clr_loader/util/find.py', line 67, in find_libmono     raise RuntimeError('Could not find libmono')     
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    
async Microsoft.Azure.WebJobs.Script.Description.WorkerFunctionInvoker.InvokeCore(Object[] parameters,FunctionInvocationContext context) 
/src/azure-functions-host/src/WebJobs.Script/Description/Workers/WorkerFunctionInvoker.cs 
 /101    
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    
async Microsoft.Azure.WebJobs.Script.Description.FunctionInvokerBase.Invoke(Object[] parameters) 
/src/azure-functions-host/src/WebJobs.Script/Description/FunctionInvokerBase.cs 
 /82    
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    
async Microsoft.Azure.WebJobs.Script.Description.FunctionGenerator.Coerce[T](Task`1 src) 
/src/azure-functions-host/src/WebJobs.Script/Description/FunctionGenerator.cs 
 /225    
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    
async Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`2.InvokeAsync[TReflected,TReturnValue](Object instance,Object[] arguments) 
D:\a\_work\1\s\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionInvoker.cs 
 /52    
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    
async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.InvokeWithTimeoutAsync(IFunctionInvoker invoker,ParameterHelper parameterHelper,CancellationTokenSource timeoutTokenSource,CancellationTokenSource functionCancellationTokenSource,Boolean throwOnTimeout,TimeSpan timerInterval,IFunctionInstance instance) 
D:\a\_work\1\s\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs 
 /581    
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    
async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithWatchersAsync(IFunctionInstanceEx instance,ParameterHelper parameterHelper,ILogger logger,CancellationTokenSource functionCancellationTokenSource) 
D:\a\_work\1\s\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs 
 /527    
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    
async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(IFunctionInstanceEx instance,FunctionStartedMessage message,FunctionInstanceLogEntry instanceLogEntry,ParameterHelper parameterHelper,ILogger logger,CancellationToken cancellationToken) 
D:\a\_work\1\s\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs 
 /306    End of inner exception    
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    
async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(IFunctionInstanceEx instance,FunctionStartedMessage message,FunctionInstanceLogEntry instanceLogEntry,ParameterHelper parameterHelper,ILogger logger,CancellationToken cancellationToken) 
D:\a\_work\1\s\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs 
 /352    
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    
async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.TryExecuteAsync(IFunctionInstance functionInstance,CancellationToken cancellationToken) 
D:\a\_work\1\s\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs 
 /108

requirements.txt中的库

azure-functions python-tabular pyadomd msal numpy pandas pymsteams azure-storage-blob
test_run.py

内的导入语句:

import pytabular
from pyadomd import Pyadomd
import requests
import json
import msal
import logging
import numpy as np
import pandas as pd
import sys
import pymsteams
from azure.storage.blob import BlobServiceClient, ContainerClient, ContentSettings
import io

def func_1():
   '''rest of the code here'''
   return df
def func_2(df1):
   '''rest of the code here'''
def main_func():
   try:
       df1 = func_1()
       func_2(df1)
   except Exception as e:
       '''some code logic to retry'''

代码在
__init__.py

import azure.functions as func
import logging
import sys
import os
from .test_run import main_func

current_dir = os.path.dirname(os.path.abspath(__file__))
sys.path.append(os.path.join(current_dir))

def main(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')
    try:
        main_func()
        name = req.params.get('name')
        if not name:
            try:
                req_body = req.get_json()
            except ValueError:
                pass
            else:
                name = req_body.get('name')
        if name:
            return func.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.")
        else:
            return func.HttpResponse(
                "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
                status_code=200
            )
    except Exception as e:
        return  func.HttpResponse(f"An error occurred: {str(e)}", status_code=500)


python-3.x azure azure-functions python-import importerror
1个回答
0
投票

然后我注意到下面。

enter image description here根据此

链接

,它仅在 Windows 操作系统中受支持。因此,当我在本地测试我的函数时,它可以工作,但部署后会出现相同的错误,因为 Linux 是 python 运行时堆栈函数应用程序唯一支持的操作系统。

enter image description here我可以看到有一个新版本的 python-tabular 可用,但其中没有任何信息是否支持 Linux。

本地输出:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.