我正在使用pyhton(3.10.9)构建Azure Function应用程序,并在部署后从应用程序中获得以下错误。我怀疑这个错误是由于函数app的操作系统,它是Linux,不支持pandas中numpy使用的“add_dll_directory”方法。当我在Visual Studio中调试应用程序时,它工作正常。任何建议,我可以如何解决这个问题?
代码:
import azure.functions as func
app = func.FunctionApp()
@app.function_name(name="myTimer")
@app.schedule(schedule="*/15 * * * *", arg_name="myTimer", run_on_startup=True, use_monitor=False)
def main(myTimer: func.TimerRequest) -> None:
from batch_functions import price_data_download, position_data_download, trade_history_download, risk_checks
import logging
price_data_download()
position_data_download()
risk_checks()
trade_history_download()
if myTimer.past_due:
logging.info('The timer is past due!')
logging.info('Python timer trigger function executed.')
Result: Failure Exception: AttributeError: module 'os' has no attribute 'add_dll_directory' Stack: File "/azure-functions-host/workers/python/3.10/LINUX/X64/azure_functions_worker/dispatcher.py", line 479,
in _handle__invocation_request call_result = await self._loop.run_in_executor( File "/usr/local/lib/python3.10/concurrent/futures/thread.py",
line 58,
in run result = self.fn(*self.args, **self.kwargs) File "/azure-functions-host/workers/python/3.10/LINUX/X64/azure_functions_worker/dispatcher.py", line 752,
in _run_sync_func return ExtensionManager.get_sync_invocation_wrapper(context, File "/azure-functions-host/workers/python/3.10/LINUX/X64/azure_functions_worker/extension.py", line 215,
in _raw_invocation_wrapper result = function(**args) File "/home/site/wwwroot/function_app.py", line 9,
in main from batch_functions import price_data_download, position_data_download, trade_history_download, risk_checks File "/home/site/wwwroot/batch_functions.py", line 1,
in <module> import pandas as pd File "/home/site/wwwroot/pandas/__init__.py", line 24,
in <module> __import__(_dependency) File "/home/site/wwwroot/numpy/__init__.py", line 112,
in <module> _delvewheel_patch_1_5_1() File "/home/site/wwwroot/numpy/__init__.py", line 109, in _delvewheel_patch_1_5_1 os.add_dll_directory(libs_dir)
1条答案
按热度按时间i1icjdpr1#
为了在Azure Function应用中正确安装Numpy,请在requirements.txt中使用**
numpy==1.25.0
来正确安装Numpy,如下所示:关于numpy库的类似问题,请参考我的SO线程答案**
requirements.txt:-
init.py:-
我的应用文件已导入
numpy==1.25.0
:-