serverless-azure-functions icon indicating copy to clipboard operation
serverless-azure-functions copied to clipboard

python: modules in requirements.txt with python virtual env are not found w/ serverless offline

Open bitsofinfo opened this issue 3 years ago • 1 comments

version: 2.1.0

  Your Environment Information ---------------------------
     Operating System:          darwin
     Node Version:              14.17.0
     Framework Version:         2.44.0
     Plugin Version:            5.2.0
     SDK Version:               4.2.3
     Components Version:        3.11.0

in the root of my project I have requirements.txt (that was autogenerated by the template) with the following in it

azure.functions
azure-functions-worker

dateparser

I did a pip install -r requirements.txt

My function just does an import dateparser

When I run serverless offline I get

[2021-06-04T15:33:10.192Z] Worker failed to function id 987f6111-c176-4314-9fb8-d64705294725.
[2021-06-04T15:33:10.192Z] Result: Failure
[2021-06-04T15:33:10.192Z] Exception: ModuleNotFoundError: No module named 'dateparser'. Troubleshooting Guide: https://aka.ms/functions-modulenotfound

bitsofinfo avatar Jun 04 '21 15:06 bitsofinfo

Note my serverless python project is using a virtual env

When I don't use a virtual env, then it works

serverless-project-root/
    my.venv/
    serverless.yml
    requirements.txt

If I source my.venv/bin/activate and serverless offline the modules are not found

If I am not using the virtual env the modules are found and everything works.

The modules are property installed within the venv

bitsofinfo avatar Jun 04 '21 16:06 bitsofinfo