我正在部署一个烧瓶网络应用程序,其机器学习模型使用xgboost进行培训。在本地工作正常,在使用Azure App服务linux机器时出错。
它似乎没有正确安装xgboost。我无法使用他们的Web SSH进行故障排除,因为它每隔几秒就会断开连接。任何人都知道如何解决它?
错误:
2019-04-05T20:46:57.927633884Z /home/site/wwwroot/antenv/lib/python3.7/site-packages/sklearn/externals/joblib/externals/cloudpickle/cloudpickle.py:47: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
2019-04-05T20:46:57.927671786Z import imp
2019-04-05T20:46:57.927678286Z [2019-04-05 20:46:57 +0000] [39] [ERROR] Exception in worker process
2019-04-05T20:46:57.927682786Z Traceback (most recent call last):
2019-04-05T20:46:57.927686887Z File "/home/site/wwwroot/antenv/lib/python3.7/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
2019-04-05T20:46:57.927691387Z worker.init_process()
2019-04-05T20:46:57.927695487Z File "/home/site/wwwroot/antenv/lib/python3.7/site-packages/gunicorn/workers/base.py", line 129, in init_process
2019-04-05T20:46:57.927700087Z self.load_wsgi()
2019-04-05T20:46:57.927703987Z File "/home/site/wwwroot/antenv/lib/python3.7/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
2019-04-05T20:46:57.927715888Z self.wsgi = self.app.wsgi()
2019-04-05T20:46:57.927720188Z File "/home/site/wwwroot/antenv/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
2019-04-05T20:46:57.927724388Z self.callable = self.load()
2019-04-05T20:46:57.927728188Z File "/home/site/wwwroot/antenv/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
2019-04-05T20:46:57.927732288Z return self.load_wsgiapp()
2019-04-05T20:46:57.927736189Z File "/home/site/wwwroot/antenv/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
2019-04-05T20:46:57.927740389Z return util.import_app(self.app_uri)
2019-04-05T20:46:57.927744389Z File "/home/site/wwwroot/antenv/lib/python3.7/site-packages/gunicorn/util.py", line 350, in import_app
2019-04-05T20:46:57.927748389Z __import__(module)
2019-04-05T20:46:57.927752289Z File "/home/site/wwwroot/app.py", line 4, in
2019-04-05T20:46:57.927756789Z import xgboost as xgb
2019-04-05T20:46:57.927760690Z File "/home/site/wwwroot/antenv/lib/python3.7/site-packages/xgboost/__init__.py", line 11, in
2019-04-05T20:46:57.927764990Z from .core import DMatrix, Booster
2019-04-05T20:46:57.927768990Z File "/home/site/wwwroot/antenv/lib/python3.7/site-packages/xgboost/core.py", line 136, in
2019-04-05T20:46:57.927773190Z _LIB = _load_lib()
2019-04-05T20:46:57.927776990Z File "/home/site/wwwroot/antenv/lib/python3.7/site-packages/xgboost/core.py", line 128, in _load_lib
2019-04-05T20:46:57.927781090Z lib.XGBGetLastError.restype = ctypes.c_char_p
2019-04-05T20:46:57.927784991Z UnboundLocalError: local variable 'lib' referenced before assignment
看起来好像没有加载xgboost模块。我建议你在启动时导入mpodule。在Docker中,您可以通过在docker文件中指定安装步骤来完成此操作。
您可以使用基于alpine的docker image的dockerfile中的步骤:https://github.com/Nexosis/alpine-xgboost/blob/master/Dockerfile
顺便说一句,我通过Github线程的讨论找到了这个:https://github.com/dmlc/xgboost/issues/3157
更多信息:执行此操作的一种方法是从此处分叉Azure App Service中使用的官方Python映像的副本:https://hub.docker.com/r/appsvc/python
完成此操作后,您可以编辑仓库中的dockerfile,并包含上面发布的解决方案中的步骤以构建您自己的docker镜像。这将确保您已加载所有模块。