Azure Functions site-packages folder in VS Code / Python

AJG 436 Reputation points
2020-07-17T08:59:30.477+00:00

I have been looking at how to include packages that are not available on the Internet in Azure function deployment, specifically: Azure Functions Python developer guide, here:

https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-python

this says that local packages can be added to the folder: app/.python_packages directory

then run the command: pip install --target="<PROJECT_DIR>/.python_packages/lib/site-packages" -r requirements.txt

to install the dependencies locally.

However, the project is already configured to run in a virtual environment, which means there is also a site-packages folder in the virtual env folder, like:

project.venv\Lib\site-packages - which is used when running locally

so - what is the correct way to set this up ?

as things stand there is one site-packages (in .python_packages) which gets uploaded and used in the server environment, and another (in .venv) which gets used when running locally - which I don't like.

is there any way to set up the virtual env to use the site-packages in .python_packages - or is there some other better way of setting things up?

A

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,605 questions
{count} votes

Accepted answer
  1. MayankBargali-MSFT 69,971 Reputation points
    2020-07-21T05:29:21.587+00:00

    Hi @AJG

    Both the steps would be necessary as the local environment (site_packages) is used when running in the virtualenv and has packages required for local development (and usually for the local OS).

    The .python_packages are required for deployment to Azure which is a Linux plan and best to keep it clean with packages listed in requirements.txt

    In a scenario where you are using Windows OS locally with C or C++ extension module which has to be built especially for that environment as azure function uses the Linux operating system and the build would be different than the Windows OS build that you are running locally.

    If you are already on Linux OS and don't want to do it twice then you can leverage below articles to update the settings/configs to achieve a single folder
    https://docs.python.org/3/using/cmdline.html#envvar-PYTHONPATH
    https://pip.pypa.io/en/stable/user_guide/#configuration


0 additional answers

Sort by: Most helpful