Home > OS >  Azure function deployment of single Python script and process of installation of requirements.txt in
Azure function deployment of single Python script and process of installation of requirements.txt in

Time:11-21

I am completely new to Azure. I recently deployed my Python Script on Azure Functions (HTTP). It worked completely fine for me. The problem I faced is when my Python script needed some packages to be installed like (pandas, psycopy2). Although I put them in requirements.txt file. And after deployment requirements.txt is stored in root directory (same as of host.json) but I am getting import error. I don't really know how to install these packages in azure function. Any help would be really really appreciated.

I tried deploying python script using multiple techniques but none of them worked for me, I just have one python script and I need to install requirement.txt file in azure function. Please help me with this problem.

CodePudding user response:

I've installed a package ('requests') and ran http trigger function locally by creating a new function app with python3.9. I was able to deploy it to Azure and triggered successfully without any error.

Note: Make sure that while adding any package in requirements.txt file, install package in the project directory folder itself by giving:

pip install  --target="<local project directory path>/.python_packages/lib/site-packages"  -r requirements.txt

Here, I've taken requests == 2.19.1 latest version package and imported in init.py

requirements.txt:

azure-functions
requests==2.19.1

While executing locally, I received the desired outcome:-

enter image description here

Deployed to Azure:

enter image description here

requirements.txt file after deploying it to Azure:

enter image description here

Received "200 Ok" response after test/run:

enter image description here

You can check here Refer MSDoc

  • Related