GettingItDone
GettingItDone

Reputation: 603

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.

Upvotes: 1

Views: 2101

Answers (2)

Jim
Jim

Reputation: 779

I know this is old, but am adding answer for those who come later (and because I have been fighting with this myself and cannot find answers anywhere). Let's face it, there are times when local development is not an option for one reason or another, so the local development docs are not helpful. This thread provided the last pieces I needed to solve the problem for a linux Function App.

NOTE -- this does not work with consumption plans

  1. SSH using development tools from your Function App in Azure portal.
  2. To see installed packages, use "pip list"
  3. To install a package, "python -m pip install "

Simple -- once you have the secret sauce! Why Microsoft can't document this is beyond me.

Upvotes: 0

suziki
suziki

Reputation: 14088

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

Upvotes: 2

Related Questions