python - 单个Python脚本的Azure函数部署以及Azure Functions中requirements.txt的安装过程

标签 python azure azure-functions azure-pipelines-yaml requirements.txt

我对 Azure 完全陌生。我最近在 Azure Functions (HTTP) 上部署了 Python 脚本。它对我来说效果很好。我面临的问题是当我的 Python 脚本需要安装一些包时,例如(pandas、psycopy2)。虽然我把它们放在requirements.txt文件中。部署后,requirements.txt 存储在根目录中(与 host.json 相同),但我收到导入错误。 我真的不知道如何在 azure 函数中安装这些包。 任何帮助将非常非常感激。

我尝试使用多种技术部署 python 脚本,但没有一种对我有用,我只有一个 python 脚本,我需要在 azure 函数中安装requirement.txt 文件。 请帮我解决这个问题。

最佳答案

我已经安装了一个软件包('requests'),并通过使用 python3.9 创建一个新函数应用在本地运行 http 触发函数。我能够将其部署到 Azure 并成功触发,没有出现任何错误。

注意:确保在 requirements.txt 文件中添加任何软件包时,安装通过给出以下内容将其打包到项目目录文件夹本身中:

pip install  --target="<local project directory path>/.python_packages/lib/site-packages"  -r requirements.txt

这里,我已经采取了 requests == 2.19.1 最新版本包并导入 init.py

requirements.txt:

azure-functions
requests==2.19.1

在本地执行时,我收到了预期的结果:-

enter image description here

部署到 Azure:

enter image description here

requirements.txt 将其部署到 Azure 后的文件:

enter image description here

测试/运行后收到“200 Ok”响应:

enter image description here

您可以在这里查看Refer MSDoc

关于python - 单个Python脚本的Azure函数部署以及Azure Functions中requirements.txt的安装过程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74492187/

相关文章:

python - 从 python3 运行 bash 命令

python - 如何立即退出Python程序但仍让线程完成

C# 如果我有私钥我该如何解密?

asp.net - 使用 Azure 表存储进行 ASP.NET session

azure - 数据工厂复制数据而不显式创建目标表

azure - 从另一个 Azure ML 工作区访问 Azure ML 模型注册表

azure - 通过将新行插入(添加)到 SQL Server 数据库表中来触发 Azure Function

azure - 在命令行上检索函数应用设置包括已删除的项目

python - urllib2/requests 不显示网页的 iframe

c# - 使用 Autofac 在我的组件类 Azure Functions 中注入(inject) ILogger 实例