我正在部署一个烧瓶Web应用程序,该应用程序具有使用xgboost训练的机器学习模型。在本地工作正常,使用Azure App Services linux计算机时出现错误。
似乎没有正确安装xgboost。我无法使用他们的网络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
答案 0 :(得分:0)
xgboost模块似乎未加载。我建议您在启动过程中导入mpodule。在Docker中,您可以通过在docker文件中指定安装步骤来执行此操作。
您可以使用基于高山的docker映像的dockerfile中的步骤:https://github.com/Nexosis/alpine-xgboost/blob/master/Dockerfile
顺便说一句,我是通过有关Github线程https://github.com/dmlc/xgboost/issues/3157
的讨论发现的更多信息: 一种实现方法是从此处https://hub.docker.com/r/appsvc/python
中复制Azure应用服务中使用的官方Python映像的副本。一旦有了这个,就可以在仓库中编辑dockerfile,并包括上面发布的解决方案中的步骤,以构建自己的docker映像。这将确保您已加载所有模块。