ModuleNotFoundError in Azure Function App Deployment
There is an issue when deploying a function app via GitHub CLI where the deployment appears to succeed, but it does not retain the packages specified in the requirements.txt
file. Running the function app locally has no problems.
The setup includes an Azure Function App using a Flexible-Consumption plan with Python 3.10 in East US 2.
The error logged in Application Insights is:
Failure Exception: ModuleNotFoundError: No module named 'requests'.
Exception while executing function: Functions.Health Result: Failure
Exception: ModuleNotFoundError: No module named 'requests'. Cannot find module. Please check the requirements.txt file for the missing module. For more info, please refer the troubleshooting guide: https://aka.ms/functions-modulenotfound. Current sys.path: ['/tmp/functions\\standby\\wwwroot', '/home/site/wwwroot/.python_packages/lib/site-packages', '/azure-functions-host/workers/python/3.10/LINUX/X64', '/usr/local/lib/python310.zip', '/usr/local/lib/python3.10', '/usr/local/lib/python3.10/lib-dynload', '/usr/local/lib/python3.10/site-packages']
Stack: File "/azure-functions-host/workers/python/3.10/LINUX/X64/azure_functions_worker/dispatcher.py", line 541, in _handle__function_load_request
func = loader.load_function(
File "/azure-functions-host/workers/python/3.10/LINUX/X64/azure_functions_worker/utils/wrappers.py", line 49, in call
raise extend_exception_message(e, message)
File "/azure-functions-host/workers/python/3.10/LINUX/X64/azure_functions_worker/utils/wrappers.py", line 44, in call
return func(*args, **kwargs)
File "/azure-functions-host/workers/python/3.10/LINUX/X64/azure_functions_worker/loader.py", line 220, in load_function
mod = importlib.import_module(fullmodname)
File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/home/site/wwwroot/Health/__init__.py", line 4, in <module>
import requests
The requirements.txt
file only contains the following entries:
azure-functions
requests
The continuous deployment configuration is based on the YML generated by the deployment center. Attempts to perform a remote build resulted in another error:
Internal error: Expected value to be neither null nor undefined: newSiteName.
Various environment variables have been toggled with no success, including:
-
SCM_DO_BUILD_DURING_DEPLOYMENT = true
-
ENABLE_ORYX_BUILD = true
-
WEBSITE_RUN_FROM_PACKAGE = <some blob location>
Additionally, different Python versions and Ubuntu versions in the YML have been tested, and there have been attempts to force the creation of the .python_packages
folder with installations managed through the YML. So the issue isn't the packages folder just missing.
An unexpected message was received from microsoft via the function app, which is displayed in the following image:
Previous suggested workarounds have been attempted and exhausted.
Further insights into why the deployment is losing the Python virtual environment created during zip deployment would be greatly appreciated.