无服务器aws python lambda无法从父目录导入模块
我有以下结构 我正在尝试在handler.py中导入utils 我试着像这样给予无服务器aws python lambda无法从父目录导入模块,python,aws-lambda,serverless-framework,Python,Aws Lambda,Serverless Framework,我有以下结构 我正在尝试在handler.py中导入utils 我试着像这样给予 from src.utils import * from utils import * 还尝试添加 import os import sys sys.path.append(os.path.dirname(os.path.realpath(__file__))) 及 但没有任何效果 我使用的是无服务器框架,而不是手动上载zip文件 试了很多,但都没用 任何帮助, 非常感谢 谢谢您可以为此使用无服务器pyth
from src.utils import *
from utils import *
还尝试添加
import os
import sys
sys.path.append(os.path.dirname(os.path.realpath(__file__)))
及
但没有任何效果
我使用的是无服务器框架,而不是手动上载zip文件
试了很多,但都没用
任何帮助,
非常感谢
谢谢您可以为此使用无服务器python需求插件 它可以安装在本地,也可以安装在带有
sls plugin install -n serverless-python-requirements
您可以将其添加到serverless.yml文件并尝试部署
# this part might not be needed depending on size of utils
custom:
pythonRequirements:
zip: true
# This plugin allows us import dependencies
plugins:
- serverless-python-requirements
在这里查看插件的指南
这很让人困惑,因为根据您提供的信息,这似乎是正确的,您是否有打字错误?或者,您在哪里看到导入错误?是部署到环境时还是从IDE中看到无法从UTIL访问任何内容?请删除src目录,并将python脚本上移到根级别。
# this part might not be needed depending on size of utils
custom:
pythonRequirements:
zip: true
# This plugin allows us import dependencies
plugins:
- serverless-python-requirements