Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing Python modules for Azure Function

How can I import modules for a Python Azure Function?

import requests

Leads to:

2016-08-16T01:02:02.317 Exception while executing function: Functions.detect_measure. Microsoft.Azure.WebJobs.Script: Traceback (most recent call last):
  File "D:\home\site\wwwroot\detect_measure\run.py", line 1, in <module>
    import requests
ImportError: No module named requests

Related, where are the modules available documented?

Related question with fully documented answer Python libraries on Web Job

like image 472
Ryan Galgon Avatar asked Aug 16 '16 01:08

Ryan Galgon


People also ask

Can we use Python in Azure function?

Although you can develop your Python-based functions locally on Windows, Python functions are supported in Azure only when they're running on Linux.

How do I add dependencies to Azure function?

Bring in dependencies from the project directoryBy putting the dependencies in a folder inside functions app project directory, the dependencies folder will get deployed together with the code. As a result, your function code can access the dependencies in the cloud via file system api.


1 Answers

You need to include a requirements.txt file with your code which lists all the python dependencies of your function

From the docs: https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-python#python-version-and-package-management

For example, your reqirements.txt file would contain:

requests==2.19.1
like image 197
Zain Rizvi Avatar answered Sep 18 '22 12:09

Zain Rizvi