【问题标题】:"ModuleNotFoundError: No module named 'django'" when trying to deploy Django server on Azure尝试在 Azure 上部署 Django 服务器时出现“ModuleNotFoundError: No module named 'django'”
【发布时间】:2020-02-15 09:31:06
【问题描述】:

在我尝试在 Azure 上部署我的 Django 网站后,我收到一条错误消息:

ModuleNotFoundError: No module named 'django'

我在我的 Django 项目的根目录中添加了一个 requirements.txt,我还有什么遗漏吗?我尝试从 Kudu BASH 安装 Django,但它卡在“清理”上。

这是完整的错误:https://pastebin.com/z5xxqM08

我使用 Django-2.2 和 Python 3.6.8 构建了网站。

【问题讨论】:

  • 一旦我拼错了requirements.txt :-) 你确定在根目录中的名字是正确的
  • @YugandharChaudhari 拼写正确
  • 您是否安装了 requirements.txt 中的内容?
  • @MatthewGaiser 我让它工作了
  • @Don 我认为这是我的 requirements.txt 没有注册 Azure 的问题。在 requirements.txt 文件中指出了那个或不正确的 Django 版本。

标签: python django azure azure-web-app-service


【解决方案1】:

只是总结为其他人的答案。根据您的错误信息,我可以看到您尝试将您的 Django 应用程序部署到基于 Docker 的 Linux 上的 Azure WebApp。所以下面有两个官方文档会有所帮助。

  1. Quickstart: Create a Python app in Azure App Service on Linux
  2. Configure a Linux Python app for Azure App Service

错误ModuleNotFoundError: No module named 'django'表示Azure Linux WebApp的容器上没有安装django包。

由于上面#2文档的Container characteristics的内容如下,

要安装附加包,例如 Django,请使用 pip freeze > requirements.txt 在项目的根目录中创建一个 requirements.txt 文件。然后,使用 Git 部署将项目发布到应用服务,它会自动在容器中运行 pip install -r requirements.txt 以安装应用的依赖项。

所以可能的原因是 requirements.txt 文件在部署后不在您的项目或容器的正确路径中,该路径应该是容器上的 /home/site/wwwroot/requirements.txt 或项目的根目录,如官方示例 Azure-Samples/djangoapp on GitHub。

【讨论】:

  • 我确实有与 OP 完全相同的问题,而且我确实在我的项目的根目录中有一个“requirements.txt”。与文档的唯一区别是我没有使用 Git Deployment,而是使用代码上传 zip 文件,但容器初始化过程仍然存在......我不明白发生了什么
猜你喜欢
  • 1970-01-01
  • 2020-03-07
  • 2020-12-28
  • 1970-01-01
  • 1970-01-01
  • 2021-08-11
  • 2020-10-05
  • 2018-11-05
  • 2020-11-01
相关资源
最近更新 更多