语言:Python 框架:Serverless v1.0
通常我会pip freeze > requirements.txt
在项目根目录中运行
如何将这些依赖项打包到每个部署中?
创造requirements.txt
点冻结> requirements.txt
创建一个包含所有依赖项的文件夹:
pip install -t vendored -r requirements.txt
请注意,为了在代码中使用这些依赖项,您需要添加以下内容:
import os
import sys
here = os.path.dirname(os.path.realpath(__file__))
sys.path.append(os.path.join(here, "./vendored"))
有关另一个示例,请参见https://stackoverflow.com/a/36944792/1111215。
更新:您现在可以使用serverless-python-requirements插件,而不是项目符号 (2) 和上面的代码:
安装插件
npm install --save serverless-python-requirements
并将插件添加到您的serverless.yml
plugins:
- serverless-python-requirements
不要忘记确保你有一个requirements.txt
文件。
就是这样,一旦sls deploy
被调用,插件就会将依赖项与代码一起打包。
有关完整示例,请查看serverless-python-sample。
我有类似的问题,采取了这些步骤来部署依赖项。 https://stackoverflow.com/a/41634501/2571060