AWS Elastic Beanstalk-Flask应用程序无法导入自定义模块 [英] AWS Elastic Beanstalk - Flask App Cannot Import Custom Module

查看:50
本文介绍了AWS Elastic Beanstalk-Flask应用程序无法导入自定义模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Python 3.6的AWS Elastic Beanstalk上托管Flask应用程序,但是无论我如何尝试,该应用程序的URL都会导致500:Internal Server Error.

I am trying to host a Flask app on AWS Elastic Beanstalk in Python 3.6, but no matter what I try, the application's url leads to a 500: Internal Server Error.

我的应用程序的结构如下:

The structure of my app is as follows:

myApp:-application.py-mytransformers.py-requirements.txt

我看了一下日志,wsgi找不到我需要的单独的python脚本,其中包含自定义Scikit-learn转换器(mytransformers.py):

I took a look at the logs, and the separate python script I need that contains custom Scikit-learn transformers (mytransformers.py) cannot be found by wsgi:

AttributeError:无法在<模块'__main __'(内置)>

我需要这些,因为我已经在导入自需要自定义转换器的 application.py 中的S3存储库中腌制了Scikit学习模型.

I need these because I have pickled Scikit-learn models in an S3 repo that I import in application.py that require custom transformers.

我试图将这些转换器定义移到我的主要 application.py 脚本中,但是它仍然返回相同的错误.

I tried to move these transformer definitions to my main application.py script but it still returns the same error.

我认为wsgi脚本无法找到这些转换器定义,而且对于遇到类似问题的人来说,我也找不到很多.

I think that the wsgi script is unable to find these transformer definitions, and I have not found much in the way of people with a similar problem.

编辑1

我尝试将 __ init __.py 文件添加到我的应用程序目录中,但仍然出现相同的错误.我要执行的操作是使用包含一些自定义转换器的Pickle加载Scikit-Learn管道,但是当我尝试加载它们时,即使我在开始时就导入了它们,也会抛出关于找不到自定义转换器的错误.的脚本.我尝试将转换器的类定义放在 application.py 脚本中,但这仍然不能解决错误.

I tried adding a __init__.py file to my application directory I am still getting the same error. What I am trying to do is load a Scikit-Learn pipeline using Pickle that contains some custom transformers, however when I try to load them it throws the error about not being able to find the custom transformers, even though I imported them at the start of the script. I tried putting the class definitions for the transformers in the application.py script but this still does not solve the error.

编辑2

我几乎可以肯定,错误是使用WSGI来管理Flask应用程序的EB.我的应用程序确实在本地运行,只是WSGI似乎无法找到帮助程序功能.我使用Azure找到了类似的帖子,但遇到类似WSGI的问题,即找不到应用程序文件中定义的函数:将Flask App部署到Azure时出现WSGI错误

I am almost certain the error is in EB using WSGI to manage the Flask app. My app does run locally, its just the WSGI that seems not able to find the helper functions. I found a similar post using Azure that had a similar problem of WSGI not finding functions defined in the application file: Error with WSGI when deploying Flask App to Azure

推荐答案

我首先将一个名为 __ init __.py 的空白文件添加到应用程序的根目录.现在, application.py 中的Flask应用程序无法检测到您的转换器,因为它们不在您的python路径上,并且它们不属于同一软件包.

I'd start by adding a blank file named __init__.py to the root of your application. Right now the Flask app in application.py can't detect your transformers because they are not on your python path, and they're not part of the same package.

添加 __ init __.py 将使您的转换器可以使用以下方式导入:从mytransformers 导入MyTransformer ,因为它将把它们添加到应用程序包中.

Adding __init__.py will make your transformers importable using: from mytransformers import MyTransformer because it will add them to the application package.

它是否在本地运行?

这篇关于AWS Elastic Beanstalk-Flask应用程序无法导入自定义模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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