Python Azure Function缺少依赖项

3
请注意:这在本地可以正常工作,但在线上 Azure 函数时会出现问题。
错误信息:
Result: Failure
Exception: ModuleNotFoundError: No module named 'pandas'
Stack:   File "/azure-functions-host/workers/python/3.6/LINUX/X64/azure_functions_worker/dispatcher.py", line 242, in _handle__function_load_request
    func_request.metadata.entry_point)
  File "/azure-functions-host/workers/python/3.6/LINUX/X64/azure_functions_worker/loader.py", line 66, in load_function
    mod = importlib.import_module(fullmodname)
  File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/home/site/wwwroot/HttpExample/__init__.py", line 20, in <module>
    import pandas as pd

导入:

import importlib



import logging

import azure.functions as func

import urllib.request
from zipfile import ZipFile
import json
import csv
import os


import pathlib
import os.path
from pathlib import Path
import time
import pandas as pd
from datetime import datetime
from dateutil.relativedelta import relativedelta

要求:

adal==1.2.2
antlr4-python3-runtime==4.7.2
applicationinsights==0.11.9
argcomplete==1.10.0
azure-cli-command-modules-nspkg==2.0.3
azure-cli-core==2.0.76
azure-cli-nspkg==3.0.4
azure-cli-profile==2.1.5
azure-cli-telemetry==1.0.4
azure-common==1.1.23
azure-functions==1.0.4
azure-mgmt-resource==4.0.0
azure-nspkg==3.0.2
bcrypt==3.1.7
certifi==2019.9.11
cffi==1.13.2
chardet==3.0.4
colorama==0.4.1
cryptography==2.8
humanfriendly==4.18
idna==2.8
isodate==0.6.0
jmespath==0.9.4
knack==0.6.3
msrest==0.6.10
msrestazure==0.6.2
numpy==1.17.3
oauthlib==3.1.0
pandas==0.25.3
paramiko==2.6.0
portalocker==1.5.1
pycparser==2.19
Pygments==2.4.2
PyJWT==1.7.1
PyNaCl==1.3.0
pyOpenSSL==19.0.0
python-dateutil==2.8.1
pytz==2019.3
PyYAML==5.1.2
requests==2.22.0
requests-oauthlib==1.2.0
six==1.12.0
tabulate==0.8.5
urllib3==1.25.6

我尝试过的方法:az account clear和az login。 如果我输入:func azure functionapp publish air-temperature

结果会出现以下错误:There was an error restoring dependencies. ERROR: cannot install cryptography-2.8 dependency: binary dependencies without wheels are not supported. Use the "--build remote" or "--build-native-deps" option to automatically build and configure the dependencies using a Docker container. More information at https://aka.ms/func-python-publish

我没有使用docker集成,所以无法使用--build-native-deps参数。

我使用的是Azure存储库将其推送到Azure存储库中,并且构建过程中没有出现任何依赖项或其他方面的错误。但是,如果我通过门户网站在线运行它,就会出现如上述顶部的错误。

我还尝试过在Python中使用venv和env,并执行pip freeze > requirements.txt。

2个回答

1

在发布时,您可以使用--no-bundler来减轻此问题。

这里是解释

在使用--build-native-deps进行常规发布期间,我们尝试使用Pyinstaller将您的requirements.txt中指定的所有自定义依赖项与我们的运行程序(worker)捆绑在一起。我们开始这样做是为了提高发布到Azure Functions后获得的启动性能。虽然这个过程有点不稳定,我们计划摆脱它。

--no-bundler标志绕过该绑定过程。因此,我们不使用Pyinstaller或任何类似模块进行临时优化。缺点是当访问API端点时可能会出现轻微延迟(冷启动)。


1
对我来说,选项--build remote在发布函数时非常有帮助。
func azure functionapp publish air-temperature --build remote

使用选项--no-bundler时,我遇到了以下错误:

警告:参数--no-bundler已被弃用且无效。Python函数应用程序不再进行捆绑。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接