Azure functions: Installing Python modules and extensions on consumption plan

后端 未结 3 2121
北荒
北荒 2020-12-05 03:43

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

3条回答
  •  爱一瞬间的悲伤
    2020-12-05 04:09

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

    • Create your Python script on Functions (let's say NameOfMyFunction/run.py)
    • Open a Kudu console
    • Go to the folder of your script (should be d:/home/site/wwwroot/NameOfMyFunction)
    • Create a virtualenv in this folder (python -m virtualenv myvenv)
    • Load this venv (cd myenv/Scripts and call activate.bat)

    Your shell should be now prefixed by (myvenv)

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

    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.

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

    Edit: 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.

提交回复
热议问题