Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Package Python Pipenv project for AWS Lambda

I have a python project and I am using pipenv to handle deps.

I need to create a zip file that includes the source code and all the dependencies code as well. I need this zip file for uploading it to AWS Lambda.

When working with pipenv, it downloads the dependency libraries somewhere in the computer, but for packaging/distribution of the project I need all the necessary code to be contained in the same place (a zip file).

Is there a way to run pipenv and set it to install dependencies at a specific path? If not, does someone knows where those dependencies are located in my machine?

Thanks

like image 507
juank11memphis Avatar asked Aug 03 '18 20:08

juank11memphis


1 Answers

This has worked for me:

#!/bin/bash

# this is b/c pipenv stores the virtual env in a different
# directory so we need to get the path to it
SITE_PACKAGES=$(pipenv --venv)/lib/python3.6/site-packages
echo "Library Location: $SITE_PACKAGES"
DIR=$(pwd)

# Make sure pipenv is good to go
echo "Do fresh install to make sure everything is there"
pipenv install

cd $SITE_PACKAGES
zip -r9 $DIR/package.zip *

cd $DIR
zip -g package.zip posts.py

I've specifically tried it with numpy and it works correctly. It includes the .so files as well which is great because everything is self contained.

like image 152
alexpotato Avatar answered Sep 21 '22 06:09

alexpotato