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:-
Deployed to Azure:
requirements.txt
file after deploying it to Azure:
Received "200 Ok" response after test/run:
You can check here Refer MSDoc