问题描述
参考“快速入门:在 Linux 上的 Azure 应用服务中创建 Python 应用” 文档,在App Service For Linux环境中部署Python应用,在添加了pandas,应用本地运行成功,但是部署到App Service后,启动报错:Application Error
问题分析
获取日志:
可以通过高级工具(kudu)连接到App Service后台,因为是Linux系统,所以通过SSH或者Bash都可以查看网站的部署文件及日志(LogFiles文件夹)。针对在启动时候就出现错误,另一种有效的方式是查看日志流:
分析日志:
2021-04-14T10:03:54 Welcome, you are now connected to log-streaming service. Starting Log Tail -n 10 of existing logs ---- ...
...
/home/LogFiles/2021_04_14_pl0sdlwk000004_default_docker.log (https://.../2021_04_14_pl0sdlwk000004_default_docker.log) 2021-04-14T07:14:56.088553959Z File "<frozen importlib._bootstrap>", line 677, in _load_unlocked 2021-04-14T07:14:56.088558258Z File "<frozen importlib._bootstrap_external>", line 728, in exec_module 2021-04-14T07:14:56.088562457Z File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed 2021-04-14T07:14:56.088566657Z File "/home/site/wwwroot/app.py", line 3, in <module> 2021-04-14T07:14:56.088571256Z import pandas 2021-04-14T07:14:56.088575055Z ModuleNotFoundError: No module named 'pandas' 2021-04-14T07:14:56.090356881Z [2021-04-14 07:14:56 +0000] [38] [INFO] Worker exiting (pid: 38) 2021-04-14T07:14:56.135086101Z [2021-04-14 07:14:56 +0000] [35] [INFO] Shutting down: Master 2021-04-14T07:14:56.135978364Z [2021-04-14 07:14:56 +0000] [35] [INFO] Reason: Worker failed to boot.
/home/LogFiles/2021_04_14_pl0sdlwk000004_docker.log (https://.../LogFiles/2021_04_14_pl0sdlwk000004_docker.log) 2021-04-14T07:08:42.143Z INFO - Stopping site test65 because it failed during startup. 2021-04-14T07:14:47.690Z INFO - Starting container for site
|
其中的原因就是因为没有成功加载pandas模块,所以应用启动失败。而在Linux的环境中,是因为在部署时候,缺少了antenv.tar.gz文件包。
问题解决
在部署时,成功导入antenv.tar.gz文件,项目运行成功
参考资料
快速入门:在 Linux 上的 Azure 应用服务中创建 Python 应用 : https://docs.azure.cn/zh-cn/app-service/quickstart-python?tabs=bash&pivots=python-framework-flask
Local git 部署:https://docs.microsoft.com/zh-cn/azure/app-service/deploy-local-git?tabs=cli