Azure features: installing Python modules and extensions on a consumption plan

I am trying to run a python script using Azure functions. I managed to upgrade the python version and install the modules on the Azure functions as part of the App Services plan, but I need to use it in accordance with the consumption plan, since my script will be run only once every day and for only a few minutes, so I want to pay only for time of completion. See: https://azure.microsoft.com/en-au/services/functions/

Now I'm still new to this, but from my understanding, the consumption plan spins 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 cannot install anything on it. I thought it would mean that I have to install it every time I spin it.

I tried installing modules through the python script itself and the kudu command line without success.

As part of the application maintenance plan, it was simple following this guide: https://prmadi.com/running-python-code-on-azure-functions-app/

+7
python virtual-machine azure azure-functions
source share
2 answers

Kudu extensions are not available in Comusumption Plan features. However, you can upgrade pip to be able to correctly install all your dependencies:

  • Create your Python script for functions (say NameOfMyFunction / run.py)
  • Open Kudu Console
  • Go to the folder where your script is located (should be d: / home / site / wwwroot / NameOfMyFunction)
  • Create virtualenv in this folder (python -m virtualenv myvenv)
  • Download this venv (cd myenv / Scripts and call activate.bat)

Your shell should now have a prefix (myvenv)

  • Update pip (python -m pip install -U pip)
  • Install what you need (python -m pip install flask)

Now in the Azure portal in the script, update 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'))) 

enter image description here

Now you can start what you want.

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

Edit: After reading the previous comment, it seems you need numpy. I just tested right now and I was able to install 1.12.1 without any problems.

+15
source share

You can download modules for the version of Python of your choice in the Consumption Plan. Please refer to the instructions at this link: https://github.com/Azure/azure-webjobs-sdk-script/wiki/Using-a-custom-version-of-Python

+2
source share

All Articles