简体   繁体   English

在gunicorn上部署flask应用程序,模块对象没有属性

[英]Deploying flask app on gunicorn, module object has no attribute

I am trying to deploy my Flask application to gunicorn and I am getting following error. 我正在尝试将Flask应用程序部署到gunicorn,但出现以下错误。

AttributeError: 'module' object has no attribute 'MyTopics'

When I run server simply the Flask server, everything works fine: 当我只运行Flask服务器的服务器时,一切正常:

python http_server/server.py

But when I run it under gunicorn, then I am getting the AttributeError 但是当我在gunicorn下运行它时,我得到了AttributeError

gunicorn -c http_server.config http_server.server:app

Loading of my server app looks like: 我的服务器应用程序的加载如下所示:

import logging
import sys
import os
import json
import time
from functools import wraps

from flask import Flask, request, jsonify

from my_lda import MyTopics

import config

logger = logging.getLogger(__name__)
app = Flask(__name__)

class Server(object):
    def __init__(self, lda_model_path):
        self.lda_model_path = lda_model_path
        self.lda_model = self.load_to_lda_model()

    def load_to_lda_model(self, path=None):
        """
        load the lda model from the specific path
        """

        if path is None:
            path = self.lda_model_path

        logger.info("loading LDA model from %r" % path)
        lda_model = MyTopics.load(path)
        logger.info("loaded LDA model %s", lda_model)
        return lda_model

logging.basicConfig(format='%(processName)s %(process)s:-%(asctime)s : %(levelname)s : %(module)s:%(lineno)d : %(funcName)s(%(threadName)s) : %(message)s')
logging.root.setLevel(level=logging.INFO)
logging.info("running %s" % ' '.join(sys.argv))

if 'MODEL_PATH' in os.environ:
    path = os.environ['MODEL_PATH']
else:
    path = config.MODEL_FILE_PATH
app.config['server'] = Server(path)

if __name__ == '__main__':
    app.run()

Calling load is based on gensim.utils.SaveLoad, but I've tried also standard pickling, but with no difference. 调用负载基于gensim.utils.SaveLoad,但我也尝试了标准酸洗,但没有区别。

My ideas so far: Can gunicorn run different Python (I'm launching it from the same virtualenv)? 到目前为止,我的想法是:gunicorn是否可以运行不同的Python(我是从同一个virtualenv启动它的)? Is it possible that gunicorn does not see some packages installed via pip install -e . gunicorn是否有可能看不到通过pip install -e .安装的某些软件包pip install -e .

EDIT: 编辑:

Adding the project structure: 添加项目结构:

  • http_server HTTP_SERVER
    • __init__.py __init__.py
    • server.py server.py
    • config.py config.py
  • data 数据
    • model.pkl model.pkl
  • __init__.py __init__.py
  • my_lda.py my_lda.py
  • setup.py setup.py

So the problem was related to the way I was pickling the MyTopics object. 因此,问题与我腌制MyTopics对象的方式有关。 More details are described in pickle can't import a module that exists? 更详细的说明在pickle中无法导入存在的模块?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Heroku 上部署 Postgres Flask 应用程序,“gunicorn.errors.AppImportError:无法在 'app' 中找到属性 'app'。” - Deploying Postgres Flask App on Heroku, "gunicorn.errors.AppImportError: Failed to find attribute 'app' in 'app'." Flask AttributeError:模块“app”没有属性“run” - Flask AttributeError: module 'app' has no attribute 'run' Flask-AttributeError:“模块”对象没有属性“ items” - Flask - AttributeError: 'module' object has no attribute 'items' 烧瓶对象没有属性app_context - Flask object has no attribute app_context 使用python模块中的gunicorn调用Flask应用 - Call a Flask app with gunicorn from python module FLASK:plotly:错误:模块“索引”没有属性“app.server” - FLASK : plotly : Error: module 'index' has no attribute 'app.server' 烧瓶蓝图属性错误:“模块”对象没有属性“名称”错误 - Flask Blueprint AttributeError: 'module' object has no attribute 'name' error PySpark + Flask + CherryPy-AttributeError:“模块”对象没有属性“树” - PySpark+Flask+CherryPy - AttributeError: 'module' object has no attribute 'tree' Flask-Superadmin-“模块”对象没有属性“ FileField” - Flask-Superadmin - 'module' object has no attribute 'FileField' Flask-Login 模块“app”没有属性“after_request” - Flask-Login module 'app' has no attribute 'after_request'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM