[英]Python & Django - 'ModuleNotFoundError: No module named 'GoalCategoryTest'' when trying to import TestCase
[英]"ModuleNotFoundError: No module named 'django'" when trying to deploy Django server on Azure
在我尝试在 Azure 上部署我的 Django 网站后,我收到一条错误消息:
ModuleNotFoundError: No module named 'django'
我在我的 Django 项目的根目录下添加了一个 requirements.txt,我是否遗漏了什么? 我尝试从 Kudu BASH 安装 Django 但它卡在“清理”中。
这是完整的错误: https://pastebin.com/z5xxqM08
我使用 Django-2.2 和 Python 3.6.8 构建了该站点。
只是总结为其他人的答案。 According to your error information, I can see that you tried to deploy your Django app to Azure WebApp on Linux based on Docker. 因此,有两个官方文件将有所帮助,如下所示。
The error ModuleNotFoundError: No module named 'django'
indicated that there is not django
package installed on the container of Azure Linux WebApp.
由于上面#2文档的Container characteristics
的内容如下,
要安装其他软件包,例如 Django,请使用
pip freeze > requirements.txt
在项目的根目录中创建一个 requirements.txt 文件。 然后,使用 Git 部署将您的项目发布到应用服务,该部署会自动在容器中运行pip install -r requirements.txt
以安装应用的依赖项。
所以可能的原因是部署后的requirements.txt
文件不在您的项目或容器的正确路径中,该路径应该是容器上的/home/site/wwwroot/requirements.txt
或您的项目的根目录,如官方示例GitHub 上Azure-Samples/djangoapp
djangoapp。
我有同样的问题。 requirements.txt
在我的存储库中,但在更改设置或重新启动服务或其他内容后,我随机开始收到相同的错误ModuleNotFoundError: No module named 'django'
。 我无能为力,更改设置或重新启动反复修复它。 最后对我有用的是:
对代码做一个小改动并提交,然后将其推送到应用服务。
这为我修好了。 现在已经发生了几次,每次这个解决方案都对我有用。 似乎 App Service 有时会进入这个 state 并且需要用这个技巧来解决?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.