I have Azure Function App in Python hosted in App Service Plan in Basic tier. I uploaded function from local VSCode to Azure Portal. Function is visible and enabled in Azure Portal. Then I installed Python venv in function root folder (using SSH in portal) and next I installed all dependencies related to this function. When function is running in Azure (trigger by TimeTrigger) it returns that particular module "is not found". What do I need to do to get this function to work properly?
The steps I took on the SSH side in the function container in Azure Portal:
-
Set up a Virtual Environment (venv):
python -m venv myenv
-
Activate the Virtual Environment:
source myenv/bin/activate
-
Install Dependencies in this venv:
pip install --target=<path-to-site-packages> -r requirements.txt
-
Verify Dependencies:
pip list
All steps above performed correctly, Python version is identical between local environment and venv, I restarted the function and unfortunately python modules imported in __init__.py
are not visible / downloaded.
I described steps which I tried.
I expected to run function app correctly with all dependencies.
2
Answers
I resolved it and it was 2 issues:
Problem of Networking with Storage - I added VNet and special configuration to firewall and it works.
So problem was that in main python file I had "import asyncio" - it was a problem for Azure, because 'asyncio' is already built-in package in Python, so since this it returned error related to 'Module Not Found'
requirements.txt
file with all the required python packages in root folder of your project.requirements.txt
is a simple text file which is used to specify the Python packages that are required by the Azure Function. When you deploy your Azure Function, the packages listed in therequirements.txt
file are installed automatically in the function’s environment.I have created a simple python Azure function locally:
Project Structure:
requirements.txt:
I have used below packages in my project:
Code Snippet:
Running locally:
Python Lunix Azure Function App with App Service Plan Basic tier
.Deployed my function to Azure Function App:
requirements.txt
.Portal response: