Package Python Pipenv project for AWS Lambda

女生的网名这么多〃 提交于 2019-12-21 17:23:23

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/51679863/package-python-pipenv-project-for-aws-lambda

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!