简体   繁体   中英

How to add Python package to Azure Function?

I am new to Azure, how do I get to install a Python package for an App Function? I followed the steps to add the required package into the requirement.txt file in the wwwroot folder. However this does not work. I also tried installing the package directly in the code ( init.py )but that doesn't work wither.

Also, I cannot access the Kudu console.

How do install the required python packages I need for my code?

  • Now Ideally, we add the requirements.txt with the source code files and deploy them together as project and during the deployment process all the dependencies will be installed.

  • Here the file structure should look like this:-在此处输入图像描述

where the requirments.txt is in the root directory of your project. Also, here I am installing flask and django along with this function. Now after we deploy this function, the packages will appear in the app service.

  • Now my http trigger function is like this where it basically returns the version of the flask package
import azure.functions as  func 
from  importlib.metadata  import  version
def  main(req: func.HttpRequest) -> func.HttpResponse: 
    return  func.HttpResponse(f"Hello, {version('flask')}. This HTTP triggered function executed successfully.")

在此处输入图像描述

Here I have deployed the function using the VScode extensions.

The other option would be to use the Console from the portal

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM