打包适用于AWS Lambda的Python Pipenv项目 [英] Package Python Pipenv project for AWS Lambda

查看:98
本文介绍了打包适用于AWS Lambda的Python Pipenv项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个python项目,我正在使用pipenv处理deps.

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

我需要创建一个包含源代码和所有依赖项代码的zip文件.我需要此zip文件才能将其上传到AWS Lambda.

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.

使用pipenv时,它将依赖库下载到计算机中的某个位置,但是为了打包/分发项目,我需要将所有必需的代码包含在同一位置(一个zip文件).

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).

是否可以运行pipenv并将其设置为在特定路径上安装依赖项?如果不是,是否有人知道这些依赖项在我的计算机中的位置?

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?

谢谢

推荐答案

这对我有用:

#!/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

我专门用numpy尝试过,它可以正常工作.它还包含.so文件,这非常好,因为所有内容都是自包含的.

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.

这篇关于打包适用于AWS Lambda的Python Pipenv项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆