Step 1: Clone this repository, which is a project I have setup to demonstrate this bug. It is a python 3.11 function app in its most basic form, with dotenv as requirement.
Step 2: Deploy this project to a Python 3.11 function app on Azure.
Expected behavior
The function app should deploy and start without errors. The /api/hello endpoint should work.
Actual behavior
An error ModuleError : No module named 'dotenv' is thrown.
Known workarounds
None
Contents of the requirements.txt file:
Provide the requirements.txt file to help us find out module related issues.
azure-functions
python-dotenv
Related information
I've ran into this problem a month ago. I have been trying to deploy my actual project for some time now, but I keep running into errors that are not logged anywhere except in screenshot above. Neither the Core Tools, the Github CI/CD Actions, the Logstream, or the App Insights logs (specifically the traces) show any error when deploying. I've managed to trace it back to the dotenv module. Removing the dotenv module from the project makes it run without problem. Locally , using func start, everything works as intended. Only when deploying it to Azure does it fail.
Source and stack trace
```python
import azure.functions as func
import dotenv
from dotenv import load_dotenv
app = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS)
@app.route('hello')
def main(req):
return func.HttpResponse("Hello World! : " + str(load_dotenv), mimetype="text/plain")
```
Microsoft.Azure.WebJobs.Script.Workers.Rpc.RpcException
Worker failed to index functions
Result: Failure Exception: ModuleNotFoundError: No module named 'dotenv'. 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.11/LINUX/X64', '/usr/local/lib/python311.zip', '/usr/local/lib/python3.11', '/usr/local/lib/python3.11/lib-dynload', '/usr/local/lib/python3.11/site-packages'] Stack: File '/azure-functions-host/workers/python/3.11/LINUX/X64/azure_functions_worker/dispatcher.py', line 348, in _handle__functions_metadata_request fx_metadata_results = self.index_functions(function_path) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File '/azure-functions-host/workers/python/3.11/LINUX/X64/azure_functions_worker/dispatcher.py', line 633, in index_functions indexed_functions = loader.index_function_app(function_path) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File '/azure-functions-host/workers/python/3.11/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.11/LINUX/X64/azure_functions_worker/utils/wrappers.py', line 44, in call return func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File '/azure-functions-host/workers/python/3.11/LINUX/X64/azure_functions_worker/loader.py', line 222, in index_function_app imported_module = importlib.import_module(module_name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File '/usr/local/lib/python3.11/importlib/init.py', line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File '/home/site/wwwroot/function_app.py', line 2, in import dotenv
Error: No module named 'dotenv', Cannot find module.
Error: No module named 'dotenv', 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.11/LINUX/X64', '/usr/local/lib/python311.zip', '/usr/local/lib/python3.11', '/usr/local/lib/python3.11/lib-dynload', '/usr/local/lib/python3.11/site-packages'] Traceback (most recent call last): File '/azure-functions-host/workers/python/3.11/LINUX/X64/azure_functions_worker/utils/wrappers.py', line 44, in call return func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File '/azure-functions-host/workers/python/3.11/LINUX/X64/azure_functions_worker/loader.py', line 222, in index_function_app imported_module = importlib.import_module(module_name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File '/usr/local/lib/python3.11/importlib/init.py', line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File '', line 1204, in _gcd_import File '', line 1176, in _find_and_load File '', line 1147, in _find_and_load_unlocked File '', line 690, in _load_unlocked File '', line 940, in exec_module File '', line 241, in _call_with_frames_removed File '/home/site/wwwroot/function_app.py', line 2, in import dotenv ModuleNotFoundError: No module named 'dotenv'
ERROR: Error: No module named 'dotenv', Cannot find module.
ERROR: Error: No module named 'dotenv', 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.11/LINUX/X64', '/usr/local/lib/python311.zip', '/usr/local/lib/python3.11', '/usr/local/lib/python3.11/lib-dynload', '/usr/local/lib/python3.11/site-packages']
No job functions found. Try making your job classes and methods
No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).
Investigative information
Please provide the following:
Repro steps
Step 1: Clone this repository, which is a project I have setup to demonstrate this bug. It is a python 3.11 function app in its most basic form, with
dotenv
as requirement. Step 2: Deploy this project to a Python 3.11 function app on Azure.Expected behavior
The function app should deploy and start without errors. The
/api/hello
endpoint should work.Actual behavior
An error
ModuleError : No module named 'dotenv'
is thrown.Known workarounds
None
Contents of the requirements.txt file:
Provide the requirements.txt file to help us find out module related issues.
Related information
I've ran into this problem a month ago. I have been trying to deploy my actual project for some time now, but I keep running into errors that are not logged anywhere except in screenshot above. Neither the Core Tools, the Github CI/CD Actions, the Logstream, or the App Insights logs (specifically the
traces
) show any error when deploying. I've managed to trace it back to thedotenv
module. Removing thedotenv
module from the project makes it run without problem. Locally , usingfunc start
, everything works as intended. Only when deploying it to Azure does it fail.Source and stack trace
```python import azure.functions as func import dotenv from dotenv import load_dotenv app = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS) @app.route('hello') def main(req): return func.HttpResponse("Hello World! : " + str(load_dotenv), mimetype="text/plain") ``` Microsoft.Azure.WebJobs.Script.Workers.Rpc.RpcException Worker failed to index functions Result: Failure Exception: ModuleNotFoundError: No module named 'dotenv'. 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.11/LINUX/X64', '/usr/local/lib/python311.zip', '/usr/local/lib/python3.11', '/usr/local/lib/python3.11/lib-dynload', '/usr/local/lib/python3.11/site-packages'] Stack: File '/azure-functions-host/workers/python/3.11/LINUX/X64/azure_functions_worker/dispatcher.py', line 348, in _handle__functions_metadata_request fx_metadata_results = self.index_functions(function_path) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File '/azure-functions-host/workers/python/3.11/LINUX/X64/azure_functions_worker/dispatcher.py', line 633, in index_functions indexed_functions = loader.index_function_app(function_path) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File '/azure-functions-host/workers/python/3.11/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.11/LINUX/X64/azure_functions_worker/utils/wrappers.py', line 44, in call return func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File '/azure-functions-host/workers/python/3.11/LINUX/X64/azure_functions_worker/loader.py', line 222, in index_function_app imported_module = importlib.import_module(module_name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File '/usr/local/lib/python3.11/importlib/init.py', line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File '/home/site/wwwroot/function_app.py', line 2, in import dotenv Error: No module named 'dotenv', Cannot find module. Error: No module named 'dotenv', 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.11/LINUX/X64', '/usr/local/lib/python311.zip', '/usr/local/lib/python3.11', '/usr/local/lib/python3.11/lib-dynload', '/usr/local/lib/python3.11/site-packages'] Traceback (most recent call last): File '/azure-functions-host/workers/python/3.11/LINUX/X64/azure_functions_worker/utils/wrappers.py', line 44, in call return func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File '/azure-functions-host/workers/python/3.11/LINUX/X64/azure_functions_worker/loader.py', line 222, in index_function_app imported_module = importlib.import_module(module_name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File '/usr/local/lib/python3.11/importlib/init.py', line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File '', line 1204, in _gcd_import File '', line 1176, in _find_and_load File '', line 1147, in _find_and_load_unlocked File '', line 690, in _load_unlocked File '', line 940, in exec_module File '', line 241, in _call_with_frames_removed File '/home/site/wwwroot/function_app.py', line 2, in import dotenv ModuleNotFoundError: No module named 'dotenv' ERROR: Error: No module named 'dotenv', Cannot find module. ERROR: Error: No module named 'dotenv', 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.11/LINUX/X64', '/usr/local/lib/python311.zip', '/usr/local/lib/python3.11', '/usr/local/lib/python3.11/lib-dynload', '/usr/local/lib/python3.11/site-packages'] No job functions found. Try making your job classes and methods No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).