如何连续交付在Azure中部署的python函数应用程序? [英] How to make a continuous delivery of a python function app deployed in Azure?

查看:62
本文介绍了如何连续交付在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部署将程序包部署到Azure.

The package is deployed to Azure using Kudu Zip deploy.

我的http触发函数在本地(在Windows上)运行良好,但是在Azure上却出现500个内部错误,因为它找不到模块请求.

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:没有名为"requests"的模块

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函数应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆