[英]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: 添加项目结构:
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.