ubuntu AttributeError:在Azure Function中导入“pandas”库时,模块“os”没有属性“add_dll_directory”

soat7uwm  于 5个月前  发布在  其他
关注(0)|答案(1)|浏览(111)

我正在努力部署一个依赖于各种库的Azure Function应用程序,包括numpy、torch和pandas(您可以在附件中找到所列的所有先决条件)。虽然应用程序在我的Ubuntu 22.0.4笔记本电脑上顺利运行,但我在部署到远程Azure Function时遇到了一个持久性问题。具体来说,我一直收到以下错误:
“AttributeError:模块”os“没有属性”add_dll_directory“。”
我提供了一个图像显示这些错误供您参考。
在我尝试解决这个问题的过程中,我探索了几个在线可用的解决方案,例如https://github.com/confluentinc/confluent-kafka-python/issues/1462Azure Function App Error: AttributeError: module 'os' has no attribute 'add_dll_directory',中概述的解决方案,但迄今为止没有一个被证明是有效的。此外,我验证init.py了本地pandas安装中的www.example.com文件不包括一行调用_delvewheel_patch_1_5_1()。因此,我怀疑这个问题可能是由于使用了一个 * 不正确版本 * 的 pandas,而不是用于 Windows而不是Linux


的数据

zfycwa2u

zfycwa2u1#

请确保您使用的是最新版本的模块。.dll文件在您的azure函数文件和提到的路径中可用。
在Azure中,您的本地路径将不起作用。
我尝试在我的简单Http触发器代码中使用方法add_dll_directory,它对我很有效。#我的目录:

Myfunction/
├── HttpTrigger1/
│  ├── __init__.py
│  ├── function.json
│  └── Dll1.dll
│
├── host.json
├── local.settings.json
└── requirements.txt
├── ...

字符串

__init__.py

import azure.functions as func
import numpy as np
import pandas as pd
import os

try:
    current_path = os.path.dirname(os.path.abspath(__file__))
    dllpath = os.path.join(current_path,'Dll1.dll')
    os.add_dll_directory(dllpath)
except AttributeError:
    pass

def main(req: func.HttpRequest) -> func.HttpResponse:
    array = np.array([1, 2, 3, 4, 5])
    dataframe = pd.DataFrame({'column': array})

    response = f"Array: {array}\n\nDataFrame:\n{dataframe}"

    return func.HttpResponse(
        response,
        mimetype="text/plain",
        status_code=200
    )

reuirements.txt

azure-functions
numpy
pandas

OUTPUT


的数据

相关问题