3

I guess many people have come across the same issue. I have tried to find every possible blog and try every method. I have reached this point and stuck here.

I am using Serverless framework and virtualenv.

serverless.yml:

 service: test-pandas
 provider:
   name: aws
   runtime: python2.7
 plugins:
   - serverless-python-requirements
 package:
    exclude:
       - venv/**
       - node_modules/**
 functions:
    hello:
       handler: validation.hello

validation.py:

import pandas as pd
import numpy as np 

def hello(event, context):
    return "hello world"

I am using python 2.7. I have run these commands in Virtualenv:

virtualenv venv --python=python2
source venv/bin/activate
pip install pandas
pip freeze > requirements.txt
cat requirements.txt

Before creating the requirements.txt, the error was "No import module named pandas" and after I setup serverless-python-requirements, I am getting "Missing required dependencies ['numpy']".

Am I missing something here?

2
  • Did you install numpy? surprised pandas didn't install it as a dependency, but ... Commented Dec 3, 2018 at 22:30
  • Yes Pandas did install Numpy by default. I can see both packages. Hence confused about the error. Commented Dec 3, 2018 at 22:39

1 Answer 1

2

I used Docker to package and deploy the Lambda function with the libraries.

Add the following in serverless.yml:

custom:
  pythonRequirements:
    dockerizePip: non-linux

Make sure Docker is running on your machine and deploy it using serverless commands. Another thing I noticed is that, after using Docker, the .zip filesize reduced almost half of the original filesize.

Sign up to request clarification or add additional context in comments.

1 Comment

if you already tried building without this solution, make sure serverless does not reuse the cache of the requirements file when deploying. if you see something like Serverless: Using static cache of requirements found at /Users/vincent/Library/Caches/serverless-python-requirements/2cf433de4980cbe5f2b691456cb28222399a8f03ff9352ad0a6e771186108712_slspyc ... remove the cache folder and deploy again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.