如何在Azure函数应用中安装python模块

6rqinv9w  于 2023-01-18  发布在  Python
关注(0)|答案(1)|浏览(160)

我需要帮助调试此代码或解决如何在Azure函数中运行此代码。它目前失败,我不确定pythons模块。假设它尝试安装,但在第一步失败
我的错误
结果:失败异常:模块未找到错误: 没有名为"azure.storage"的模块堆栈: 文件"/azure-functions-host/worker/python/3.8/LINUX/X64/azure_functions_worker/www.example.com ",第458行,在_handle__invocation_request中调用_result =等待自身。_loop. run_in_executor(文件"/usr/local/lib/python3.8/concurrent/futures/www.example.com",第57行,在运行结果=自身。fndispatcher.py文件"/azure-functions-host/worker/python/3.8/LINUX/X64/azure_functions_worker/www.example.com ",第215行,原始调用 Package 结果=函数thread.py", line 57, in run result = self.fn(*self.args,**self.kwargs) File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/dispatcher.py", line 701, in _run_sync_func return ExtensionManager.get_sync_invocation_wrapper(context, File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/extension.py", line 215, in _raw_invocation_wrapper result = function(**args) File "/home/site/wwwroot/httptrigger-pmaas-data-transformation/init.py", line 30, in main from .run_transformation import run File "/home/site/wwwroot/httptrigger-pmaas-data-
我的__姓名首字母

import azure.functions as func 
import logging
import os
from subprocess import check_call
try:
    check_call(['python3', '-m', 'pip', 'install', 'numpy==1.21.4'])
    check_call(['python3', '-m', 'pip', 'install', 'pandas==1.2.4'])
    check_call(['python3', '-m', 'pip', 'install', 'azure-storage-blob==12.8.0'])
    check_call(["python3", '-m', 'pip', 'install', 'openpyxl==3.0.10'])
    from .run_transformation import run
    from azure.storage.blob import BlobServiceClient
except:
    pass  def main(req: func.HttpRequest) -> func.HttpResponse:
    try:
        check_call(['python3', '-m', 'pip', 'install', 'numpy==1.21.4'])
        check_call(['python3', '-m', 'pip', 'install', 'pandas==1.2.4'])
        check_call(['python3', '-m', 'pip', 'install', 'azure-storage-blob==12.8.0'])
        check_call(["python3", '-m', 'pip', 'install', 'openpyxl==3.0.10'])
        from .run_transformation import run
        from azure.storage.blob import BlobServiceClient
    except:
        check_call(['python3', '-m', 'pip', 'install', 'numpy==1.21.4'])
        check_call(['python3', '-m', 'pip', 'install', 'pandas==1.2.4'])
        check_call(['python3', '-m', 'pip', 'install', 'azure-storage-blob==12.8.0'])
        check_call(["python3", '-m', 'pip', 'install', 'openpyxl==3.0.10'])
        from .run_transformation import run
        from azure.storage.blob import BlobServiceClient
    logging.info('Starting Data Transformation')
    connectionString = os.environ['SA_CONNECTION_STRING']
    exceptions = run(connectionString)     if len(exceptions) > 0:
        return func.HttpResponse(
            "Failed! :: One more files were not processed. List of exceptions. {exceptions}",
            status_code=200
        )
    return func.HttpResponse(
            "Success! :: Data Transfomration is completed. Check log for more details and troubleshooting",
            status_code=200
    )

谢谢

67up9zun

67up9zun1#

您要安装的模块应包含在requirements.txt文件中。requirements.txt * 包含发布到Azure时系统安装的Python包的列表。* 假设您使用的是v1编程模型,您可以在此处找到更多详细信息。
在您的情况下,requirements.txt文件将包含相应的模块...

numpy==1.21.4
pandas==1.2.4
azure-storage-blob==12.8.0
openpyxl==3.0.10

...然后将在发布过程中安装,以便您像往常一样将它们导入到代码中。
希望这个有用。

相关问题