pythonmoduleazure-functions

Cannot install packages for Python Azure Function


I have a Python Azure function which executes locally. It is deployed to Azure and I selected the 'free app plan'. The Python has dependencies on various modules, such as requests. The modules are not loaded into the app like they are locally on my machine. The function fails when triggered.


Solution

  • You can find a requirements.txt in your local function folder.

    If you want function on azure to install the 'requests', your requirements.txt should be like this:(Azure will install the extension based on this file)

    azure-functions
    requests
    

    And all these packages will be packaged into a new package on Azure, so you can not display which packages using pip list. Also, please keep in mind that Linux's Kudu feature is limited and you cannot install packages through it.

    Problem seems comes from VS Code, you can use command to deploy your function app.

    For example, my functionapp on Azure named 423PythonBowman2, So this is my command:

    func azure functionapp publish 423PythonBowman --build remote
    

    I quoted requests in the code, and with cmd deploy my function can works fine on portal with no errors.

    Have a look of the offcial doc:

    https://learn.microsoft.com/en-us/azure/azure-functions/functions-run-local?tabs=macos%2Ccsharp%2Cbash#publish