How to make a continuous delivery of a python function app deployed in Azure?(如何持续交付部署在 Azure 中的 Python 函数应用程序?)
问题描述
我第一次使用部署管道将 Python 函数应用部署到 Azure:
For the first time I deployed a Python function app to Azure using a deployment pipeline:
https://docs.microsoft.com/bs-latn-ba/azure/azure-functions/functions-how-to-azure-devops
使用 Kudu Zip deploy 将包部署到 Azure.
The package is deployed to Azure using Kudu Zip deploy.
我的 http 触发函数在本地(在 Windows 上)运行良好,但我在 Azure 上出现 500 个内部错误,因为它找不到模块 requests.
My http triggered function runs wonderfully locally (on Windows), but I have a 500 internal errors on Azure because it does not find the module requests.
异常:ModuleNotFoundError:没有名为请求"的模块
Exception: ModuleNotFoundError: No module named 'requests'
__init__.py 的导入:
imports of __init__.py:
import logging, requests, os
import azure.functions as func
如果我删除请求"依赖项,该函数可在 Azure 上运行(状态 200).
If I remove the 'requests' dependency the function works on Azure (status 200).
请求库由 requirement.txt 导入,并由构建管道复制到 .venv36/lib/site-packages/requests.
The requests library is imported by the requirement.txt and copied to the .venv36/lib/site-packages/requests by the build pipeline.
所以我想知道包中内置的虚拟环境 .venv36 是否被 Azure 中部署的功能使用.没有说明如何在 Azure 中激活虚拟环境.
So I am wondering if the virtual environment .venv36 that is built in the package is used by the function deployed in Azure. There is no indication about how to activate virtual environments in Azure.
推荐答案
如果您将虚拟环境 worker_venv
命名为您链接的文档中的名称,它应该可以工作(假设您使用的是 Linux 环境用于您的管道).
If you name your virtual env worker_venv
as named in the documentation you linked, it should work (assuming you are using a Linux environment for your pipeline).
但是,Python Azure Functions 文档很快就会更新,推荐的方法是不要从部署管道部署整个虚拟环境.相反,您希望将软件包安装在 .python_packages/lib/site-packages
中.
However, the Python Azure Functions documentation is to be updated very soon, and the recommended way would be to not deploy the entire virtual environment from your deployment pipeline.
Instead, you'd want to install your packages in .python_packages/lib/site-packages
.
你可以这样做——
pip3.6 install --target .python_packages/lib/site-packages -r requirements.txt
而不是--
python3.6 -m venv worker_venv
source worker_venv/bin/activate
pip3.6 install setuptools
pip3.6 install -r requirements.txt
它应该可以正常工作.
这篇关于如何持续交付部署在 Azure 中的 Python 函数应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何持续交付部署在 Azure 中的 Python 函数应用程序?


- 计算测试数量的Python单元测试 2022-01-01
- ";find_element_by_name(';name';)";和&QOOT;FIND_ELEMENT(BY NAME,';NAME';)";之间有什么区别? 2022-01-01
- 检查具有纬度和经度的地理点是否在 shapefile 中 2022-01-01
- 我如何卸载 PyTorch? 2022-01-01
- 使用公司代理使Python3.x Slack(松弛客户端) 2022-01-01
- YouTube API v3 返回截断的观看记录 2022-01-01
- 如何使用PYSPARK从Spark获得批次行 2022-01-01
- 使用 Cython 将 Python 链接到共享库 2022-01-01
- CTR 中的 AES 如何用于 Python 和 PyCrypto? 2022-01-01
- 我如何透明地重定向一个Python导入? 2022-01-01