Fehler beim Bereitstellen von Python-Code für eine Linux-basierte Azure-FunktionPython

Python-Programme
Anonymous
 Fehler beim Bereitstellen von Python-Code für eine Linux-basierte Azure-Funktion

Post by Anonymous »

Ich versuche, Python-Code für die Azure-Funktion bereitzustellen (Linux-basiert, Python 3.12). Allerdings erhalte ich auf Azure die folgende Fehlermeldung:

Code: Select all

> ImportError: Unable to import required dependencies: numpy: Error
> importing numpy: you should not try to import numpy from
>         its source directory; please exit the numpy source tree, and relaunch
>         your python interpreter from there. Cannot find module. Please check the requirements.txt file for the missing module. For more info,
Die Azure-Funktions-App verwendet den App Service-Plan.
Bitte finden Sie unten den Python-Code und andere abhängige Dateien:
function_app.py

Code: Select all

import azure.functions as func
import logging
import json
import pandas
import numpy
import statsmodels.api as sm
from scipy import stats

@app.route(route="health_check", methods=["GET"])
async def health_check(req: func.HttpRequest) -> func.HttpResponse:
# Basic usage of pandas
df = pandas.DataFrame({'A': [1, 2], 'B': [3, 4]})
pandas_result = df.sum().to_dict()
print(pandas_result)

# Basic usage of numpy
np_result = float(numpy.mean([1, 2, 3]))
print(np_result)

# Basic usage of statsmodels

X = [1, 2, 3]
y = [2, 4, 6]
X_const = sm.add_constant(X)
model = sm.OLS(y, X_const)
results = model.fit()
sm_result = float(results.params[1])  # Slope
print(sm_result)
# Basic usage of scipy

scipy_result = float(stats.pearsonr(X, y)[0])  # Correlation
print(scipy_result)

result = {
"pandas_sum": pandas_result,
"numpy_mean": np_result,
"statsmodels_slope": sm_result,
"scipy_correlation": scipy_result
}
return func.HttpResponse(json.dumps(result), status_code=200, mimetype="application/json")
requirements.txt

Code: Select all

azure-functions
pandas==2.3.2
numpy==2.2.6
statsmodels==0.14.5
scipy==1.15.3
Ich verwende Windows, daher erstelle ich Pakete lokal mit dem folgenden Befehl:

Code: Select all

py -m pip install --target=".python_packages/lib/site-packages" -r requirements.txt --only-binary=:all: --upgrade --platform manylinux2014_x86_64
und erstellen Sie eine ZIP-Datei mit den folgenden Dateien/Ordnern:

Code: Select all

function_app.py
host.json
requirements.txt
.funcignore
.python_packages
Übersehe ich irgendwelche Schritte?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post