在gunicorn上部署flask app,模块对象没有属性
Deploying flask app on gunicorn, module object has no attribute
我正在尝试将我的 Flask 应用程序部署到 gunicorn,但出现以下错误。
AttributeError: 'module' object has no attribute 'MyTopics'
当我 运行 服务器只是 Flask 服务器时,一切正常:
python http_server/server.py
但是当我 运行 它在 gunicorn 下时,我得到 AttributeError
gunicorn -c http_server.config http_server.server:app
我的服务器应用程序加载如下:
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()
调用负载基于 gensim.utils.SaveLoad,但我也尝试过标准酸洗,但没有区别。
我目前的想法:gunicorn 运行 可以不同 Python (我从同一个 virtualenv 启动它)吗? gunicorn 是否有可能看不到通过 pip install -e .
安装的某些软件包
编辑:
添加项目结构:
- http_server
- __init__.py
- server.py
- config.py
- 数据
- model.pkl
- __init__.py
- my_lda.py
- setup.py
所以问题与我处理 MyTopics 对象的方式有关。
pickle can't import a module that exists?
中描述了更多详细信息
我正在尝试将我的 Flask 应用程序部署到 gunicorn,但出现以下错误。
AttributeError: 'module' object has no attribute 'MyTopics'
当我 运行 服务器只是 Flask 服务器时,一切正常:
python http_server/server.py
但是当我 运行 它在 gunicorn 下时,我得到 AttributeError
gunicorn -c http_server.config http_server.server:app
我的服务器应用程序加载如下:
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()
调用负载基于 gensim.utils.SaveLoad,但我也尝试过标准酸洗,但没有区别。
我目前的想法:gunicorn 运行 可以不同 Python (我从同一个 virtualenv 启动它)吗? gunicorn 是否有可能看不到通过 pip install -e .
编辑:
添加项目结构:
- http_server
- __init__.py
- server.py
- config.py
- 数据
- model.pkl
- __init__.py
- my_lda.py
- setup.py
所以问题与我处理 MyTopics 对象的方式有关。 pickle can't import a module that exists?
中描述了更多详细信息