Azure 函数 GDAL 支持

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

我有一个 python 项目 a,它在 azure 函数上运行。这也需要 GDAL 库。对于当前安装gdal的设置,我使用了wheel安装方法,但是当我将python版本从3.10更改为3.11时,没有适用于Linux的wheel,这个问题有什么解决方案吗?

目前的安装方式

在req.txt文件中包含

/gdal.whl

尝试找到基于linux的python 3.11的GDAL轮。没有任何可用的方法可以在 azure 函数中安装 gdal(基于 Linux)

python pip azure-functions gdal
1个回答
0
投票

您可以在 Python 3.11 Azure Functions 中安装 GDAL-3.6.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

项目结构:

│   .funcignore
│   .gitignore
│   function_app.py
│   host.json
│   local.settings.json
│   requirements.txt
├───.python_packages
├───.vscode
├───env
└───wheelhouse
        GDAL-3.6.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • 在requirements.txt中给出GDAL文件的路径。

需求.txt:

azure-functions
./wheelhouse/GDAL-3.6.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

功能代码片段:

import datetime
import json
import logging

import azure.functions as func
from osgeo import gdal

app = func.FunctionApp()

@app.route(route="http_trigger", auth_level=func.AuthLevel.ANONYMOUS)
def http_trigger(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')

    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. Gdal Version is: "+gdal.__version__,
             status_code=200
        )
  • 将功能部署到Azure:
  • 能够安装GDAL包:

enter image description here

控制台响应:

(env) C:\Users\uname\pyfunc>func azure functionapp publish functionappname

Getting site publishing info...
[2024-04-04T07:52:43.144Z] Starting the function app deployment...
Creating archive for current directory...
Performing remote build for functions project.
Deleting the old .python_packages directory
Uploading 64.16 MB [##############################################################################]
Remote build in progress, please wait...
Updating submodules.
Preparing deployment for commit id '98935773-e'.
PreDeployment: context.CleanOutputPath False
PreDeployment: context.OutputPath /home/site/wwwroot
Repository path is /tmp/zipdeploy/extracted
Running oryx build...
Command: oryx build /tmp/zipdeploy/extracted -o /tmp/build/expressbuild --platform python --platform-version 3.11 -i /tmp/8dc547c5e3a49e4 -p packagedir=.python_packages/lib/site-packages
Operation performed by Microsoft Oryx, https://github.com/Microsoft/Oryx
You can report issues at https://github.com/Microsoft/Oryx/issues

Oryx Version: 0.2.20230508.1, Commit: 7fe2bf39b357dd68572b438a85ca50b5ecfb4592, ReleaseTagName: 20230508.1

Build Operation ID: d7bf2b863788d653
Repository Commit : 98935773-eeb5-47cd-b1be-dce6142af983
OS Type           : bullseye
Image Type        : githubactions

Detecting platforms...
Detected following platforms:
  python: 3.11.8

Using intermediate directory '/tmp/8dc547c5e3a49e4'.

Copying files to the intermediate directory...
Done in 0 sec(s).

Source directory     : /tmp/8dc547c5e3a49e4
Destination directory: /tmp/build/expressbuild

Python Version: /tmp/oryx/platforms/python/3.11.8/bin/python3.11
Creating directory for command manifest file if it does not exist
Removing existing manifest file

Running pip install...
Done in 4 sec(s).
[07:53:56+0000] Processing ./wheelhouse/GDAL-3.6.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
[07:53:56+0000] Collecting azure-functions
[07:53:56+0000]   Downloading azure_functions-1.18.0-py3-none-any.whl (173 kB)
[07:53:56+0000] Installing collected packages: GDAL, azure-functions
[07:53:59+0000] Successfully installed GDAL-3.6.4 azure-functions-1.18.0
WARNING: You are using pip version 21.2.4; however, version 24.0 is available.
You should consider upgrading via the '/tmp/oryx/platforms/python/3.11.8/bin/python3.11 -m pip install --upgrade pip' command.
Not a vso image, so not writing build commands
Preparing output...

Copying files to destination directory '/tmp/build/expressbuild'...
Done in 3 sec(s).

Removing existing manifest file
Creating a manifest file...
Manifest file created.
Copying .ostype to manifest output directory.

Done in 7 sec(s).
Writing the artifacts to a Zip file
Running post deployment command(s)...

Generating summary of Oryx build
Deployment Log file does not exist in /tmp/oryx-build.log
The logfile at /tmp/oryx-build.log is empty. Unable to fetch the summary of build
Triggering recycle (preview mode disabled).
Deployment successful. deployer = Push-Deployer deploymentPath = Functions App ZipDeploy. Extract zip. Remote build.
Remote build succeeded!

传送门:

  • 我可以看到
    Gdal Version 3.6.4
    已安装在门户中:

enter image description here

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