Hello,
I got an error while deploying azure python function using cicd pipeline. The error is ModuleNotFoundError: No module named 'azure.servicebus'.
But the case is, service-bus module already installing while building the package on cicd pipeline.
When direct deploying using vscode or azure cli, the Function app works fine without any error.
-
working environment and function app python version – 3.7
azure function app version – 3.x
cicd pipeline agent specification – ubuntu-latest
This error occurs when a function is executed. The function app was deployed using the CiCd pipeline and all dependencies are include in requirements.txt as shown below.
Here is the pipeline build bash script
Could anyone please help?
2
Answers
I am able to reproduce your issue:
And I can fix this issue:
I know what you are doing. Create virtual environment, active virtual environment, install python packages to the virtual environment…
And you mentioned VS Code/CLI deploy is no problem.
Yes, as you observe, everything should be installed successfully to the virtual environment.
The reason is both of VS Code Deploy and CLI deploy doesn’t have any relationship with virtual environment, these deployment method only care the requirements.txt file, they don’t check others.
And, those operations you done is only work on current agent machine, azure function app you deploy to is another situation. It is a new machine, a new environment.
So you just need to simply design the pipeline like this:
Working principle of VS Code and CLI
https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-python?tabs=asgi%2Capplication-level#remote-build
This help me to resolve the issue
Instead of pip install -r requirements.txt use pip install –target="./.python_packages/lib/site-packages" -r ./requirements.txt
https://github.com/Azure/azure-functions-python-worker/issues/708