Azure功能:在使用计划上安装Python模块和扩展 [英] Azure functions: Installing Python modules and extensions on consumption plan

查看:88
本文介绍了Azure功能:在使用计划上安装Python模块和扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Azure函数运行python脚本. 我在App Services计划下成功更新了python版本并在Azure功能上安装了模块,但是我需要在Consumption计划下使用它,因为我的脚本每天只会执行一次,并且只执行几分钟,所以我只想为此付费执行时间.请参阅: https://azure.microsoft.com/en-au/services/functions/

I am trying to run a python script with Azure functions. I had success updating the python version and installing modules on Azure functions under the App Services plan but I need to use it under the Consumption plan as my script will only execute once everyday and for only a few minutes, so I want to pay only for the time of execution. See: https://azure.microsoft.com/en-au/services/functions/

现在,我仍然是新手,但是据我了解,使用计划会启动vm并在执行脚本后终止它,这与始终启用的App Service计划不同. 我不确定为什么这意味着我不能在上面安装任何东西.我以为那只是意味着每次旋转时都必须安装它.

Now I'm still new to this but from my understanding the consumption plan spins up the vm and terminates it after your script has been executed unlike the App Service plan which is always on. I am not sure why this would mean that I can't have install anything on it. I thought that would just mean I have to install it every time I spin it up.

我尝试通过python脚本本身和kudu命令行安装模块,但没有成功.

I have tried installing modules through the python script itself and the kudu command line with no success.

在应用服务计划下很简单,请按照本教程进行操作: https://prmadi.com/running-python-code-on-azure-functions-app/

While under the app service plan it was simple, following this tutorial: https://prmadi.com/running-python-code-on-azure-functions-app/

推荐答案

在功能消耗"计划中,Kudu扩展不可用.但是,您可以更新pip以便能够正确安装所有依赖项:

On Functions Comsumption plan, Kudu extensions are not available. However, you can update pip to be able to install all your dependencies correctly:

  • 在Functions上创建Python脚本(假设NameOfMyFunction/run.py)
  • 打开Kudu控制台
  • 转到脚本的文件夹(应为d:/home/site/wwwroot/NameOfMyFunction)
  • 在此文件夹中创建virtualenv(python -m virtualenv myvenv)
  • 加载此venv(cd myenv/脚本并调用activate.bat)

您的外壳现在应该以(myvenv)为前缀

Your shell should be now prefixed by (myvenv)

  • 更新pip(python -m pip安装-U pip)
  • 安装所需组件(python -m pip安装瓶)

现在在Azure门户的脚本中,更新sys.path以添加该venv:

Now in the Azure Portal, in your script, update the sys.path to add this venv:

import sys, os.path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname( __file__ ), 'myvenv/Lib/site-packages')))

您应该现在就可以开始想要的事情.

You should be able to start what you want now.

(参考: https://github.com/Azure/azure -sdk-for-python/issues/1044 )

阅读先前的评论,看来您需要numpy.我现在刚刚进行了测试,并且能够毫无问题地安装1.12.1.

reading previous comment, it seems you need numpy. I just tested right now and I was able to install 1.12.1 with no issues.

这篇关于Azure功能:在使用计划上安装Python模块和扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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