0
我試圖將我的Flask應用程序部署到gunicorn,並且出現以下錯誤。在gunicorn上部署flask應用程序,模塊對象沒有任何屬性
AttributeError: 'module' object has no attribute 'MyTopics'
當我運行服務器簡單的瓶服務器,一切正常:
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
描述是Mytopic用戶定義的函數提供全程追溯 – The6thSense
它只是使用來自'gensim.utils.SaveLoad'繼承的方法和自負荷跟蹤是:'文件「/Users/user/.virtualenvs /project_data/lib/python2.7/site-packages/gensim/utils.py「,第261行,載入中 obj = unpickle(fname) 文件」/Users/user/.virtualenvs/project_data/lib/python2.7 /site-packages/gensim/utils.py「,第842行,在unpickle return _pickle.load(f) AttributeError:'模塊'對象沒有屬性'MyTopics'' – ziky90
我在最近的編輯中添加了項目結構。 – ziky90